Skip to content

Commit 371f9ad

Browse files
committed
fix lexically_normal for ../foo/../../bar/
* originally this was "normalizing" to `"bar"` when it should be `"../../bar"` * this fixes gulrak#185
1 parent b1982f0 commit 371f9ad

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

include/ghc/filesystem.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,11 +3261,12 @@ GHC_INLINE path path::lexically_normal() const
32613261
continue;
32623262
}
32633263
else if (s == ".." && !dest.empty()) {
3264-
auto root = root_path();
3265-
if (dest == root) {
3264+
if (dest == root_path()) {
32663265
continue;
32673266
}
3268-
else if (*(--dest.end()) != "..") {
3267+
3268+
const auto filename = *(--dest.end());
3269+
if (filename != ".." && !(filename.empty() && dest.has_parent_path() && dest.parent_path() == "..")) {
32693270
if (dest._path.back() == preferred_separator) {
32703271
dest._path.pop_back();
32713272
}

test/filesystem_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ TEST_CASE("fs.path.gen - path generation", "[filesystem][path][fs.path.gen]")
955955
CHECK(fs::path("ab/cd/ef/../../qw").lexically_normal() == "ab/qw");
956956
CHECK(fs::path("a/b/../../../c").lexically_normal() == "../c");
957957
CHECK(fs::path("../").lexically_normal() == "..");
958+
CHECK(fs::path("../foo/../../bar/").lexically_normal() == "../../bar/");
958959
#ifdef GHC_OS_WINDOWS
959960
CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/");
960961
CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");

0 commit comments

Comments
 (0)