summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPavel Boldin <pboldin@cloudlinux.com>2024-03-15 15:21:16 (GMT)
committerPavel Boldin <boldin.pavel@gmail.com>2024-03-16 16:08:06 (GMT)
commite5413d3cc13a3a9de0b8ca6faadb813270687cba (patch)
tree006b2f7cf5e4ce17feabc986ffe699a49559b347 /src
parentab510c7a8cccbea0ea2c82531dc23893b551d55e (diff)
downloadNinja-e5413d3cc13a3a9de0b8ca6faadb813270687cba.zip
Ninja-e5413d3cc13a3a9de0b8ca6faadb813270687cba.tar.gz
Ninja-e5413d3cc13a3a9de0b8ca6faadb813270687cba.tar.bz2
CanonicalizePath: fix 'a/b/.._foo' -> 'a' replacement
Signed-off-by: Pavel Boldin <pboldin@cloudlinux.com>
Diffstat (limited to 'src')
-rw-r--r--src/util.cc2
-rw-r--r--src/util_test.cc4
2 files changed, 5 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index 5f67fcf..b510a9b 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -253,7 +253,7 @@ void CanonicalizePath(char* path, size_t* len, uint64_t* slash_bits) {
if (src[0] == '.') {
if (component_len == 1)
break; // Ignore trailing '.' (e.g. 'foo/.' -> 'foo/')
- if (src[1] == '.') {
+ if (component_len == 2 && src[1] == '.') {
// Handle '..'. Back up if possible.
if (component_count > 0) {
while (--dst > dst0 && !IsPathSeparator(dst[-1])) {
diff --git a/src/util_test.cc b/src/util_test.cc
index 8467e2a..d76954c 100644
--- a/src/util_test.cc
+++ b/src/util_test.cc
@@ -152,6 +152,10 @@ TEST(CanonicalizePath, PathSamples) {
path = "foo/..";
CanonicalizePath(&path);
EXPECT_EQ(".", path);
+
+ path = "foo/.._bar";
+ CanonicalizePath(&path);
+ EXPECT_EQ("foo/.._bar", path);
}
#ifdef _WIN32