Commit 9f2c11f5 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[d8] Fix NormalizePath with relative paths

Bug: v8:12060
Change-Id: Ie78329cd6e9f8b19e3be0ccc0c14ae4a1995fb9d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3098189Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76337}
parent d620467f
......@@ -854,16 +854,21 @@ std::string NormalizePath(const std::string& path,
std::string segment;
while (std::getline(segment_stream, segment, '/')) {
if (segment == "..") {
segments.pop_back();
if (!segments.empty()) segments.pop_back();
} else if (segment != ".") {
segments.push_back(segment);
}
}
// Join path segments.
std::ostringstream os;
if (segments.size() > 1) {
std::copy(segments.begin(), segments.end() - 1,
std::ostream_iterator<std::string>(os, "/"));
os << *segments.rbegin();
} else {
os << "/";
if (!segments.empty()) os << segments[0];
}
return os.str();
}
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const paths = [
".",
"..",
"...",
"/",
"/..",
"/../..",
"../..",
"./..",
"./../",
"./../..",
];
const results = await Promise.allSettled(paths.map(path => import(path)));
for (let result of results) {
assertEquals(result.status, 'rejected');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment