fix lexically_normal for ../foo/../../bar/

* originally this was "normalizing" to `"bar"` when it should be `"../../bar"`
* this fixes #185
This commit is contained in:
Mike Gevaert 2024-11-05 13:57:42 +01:00
parent b1982f06c8
commit 371f9ad1f8
2 changed files with 5 additions and 3 deletions

View File

@ -3261,11 +3261,12 @@ GHC_INLINE path path::lexically_normal() const
continue;
}
else if (s == ".." && !dest.empty()) {
auto root = root_path();
if (dest == root) {
if (dest == root_path()) {
continue;
}
else if (*(--dest.end()) != "..") {
const auto filename = *(--dest.end());
if (filename != ".." && !(filename.empty() && dest.has_parent_path() && dest.parent_path() == "..")) {
if (dest._path.back() == preferred_separator) {
dest._path.pop_back();
}

View File

@ -955,6 +955,7 @@ TEST_CASE("fs.path.gen - path generation", "[filesystem][path][fs.path.gen]")
CHECK(fs::path("ab/cd/ef/../../qw").lexically_normal() == "ab/qw");
CHECK(fs::path("a/b/../../../c").lexically_normal() == "../c");
CHECK(fs::path("../").lexically_normal() == "..");
CHECK(fs::path("../foo/../../bar/").lexically_normal() == "../../bar/");
#ifdef GHC_OS_WINDOWS
CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/");
CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");