mirror of
https://github.com/gulrak/filesystem.git
synced 2025-12-07 01:06:38 +08:00
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:
parent
b1982f06c8
commit
371f9ad1f8
@ -3261,11 +3261,12 @@ GHC_INLINE path path::lexically_normal() const
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (s == ".." && !dest.empty()) {
|
else if (s == ".." && !dest.empty()) {
|
||||||
auto root = root_path();
|
if (dest == root_path()) {
|
||||||
if (dest == root) {
|
|
||||||
continue;
|
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) {
|
if (dest._path.back() == preferred_separator) {
|
||||||
dest._path.pop_back();
|
dest._path.pop_back();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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("ab/cd/ef/../../qw").lexically_normal() == "ab/qw");
|
||||||
CHECK(fs::path("a/b/../../../c").lexically_normal() == "../c");
|
CHECK(fs::path("a/b/../../../c").lexically_normal() == "../c");
|
||||||
CHECK(fs::path("../").lexically_normal() == "..");
|
CHECK(fs::path("../").lexically_normal() == "..");
|
||||||
|
CHECK(fs::path("../foo/../../bar/").lexically_normal() == "../../bar/");
|
||||||
#ifdef GHC_OS_WINDOWS
|
#ifdef GHC_OS_WINDOWS
|
||||||
CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/");
|
CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/");
|
||||||
CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");
|
CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user