mirror of
https://github.com/gulrak/filesystem.git
synced 2026-07-30 16:26:11 +08:00
Fix lexically_normal() to correctly preserve unresolved parent components in relative paths
This commit is contained in:
parent
8ae8ec1582
commit
87157acd6c
@ -651,6 +651,9 @@ to the expected behavior.
|
||||
* Fix for [#203](https://github.com/gulrak/filesystem/issues/203), directory
|
||||
iteration and `proximate()` are available in builds without exception
|
||||
support, with iteration errors terminating the process.
|
||||
* Fix for [#185](https://github.com/gulrak/filesystem/issues/185),
|
||||
`lexically_normal()` now preserves unresolved parent components in relative
|
||||
paths.
|
||||
* Pull requests [#198](https://github.com/gulrak/filesystem/pull/198) and
|
||||
[#199](https://github.com/gulrak/filesystem/pull/199), updated CI for current
|
||||
runners and compiler toolchains, retaining legacy compiler and MSVC v142
|
||||
|
||||
@ -3269,7 +3269,12 @@ GHC_INLINE path path::lexically_normal() const
|
||||
if (dest == root) {
|
||||
continue;
|
||||
}
|
||||
else if (*(--dest.end()) != "..") {
|
||||
else {
|
||||
auto last = --dest.end();
|
||||
if (last->empty() && last != dest.begin()) {
|
||||
--last;
|
||||
}
|
||||
if (!last->empty() && *last != "..") {
|
||||
if (dest._path.back() == preferred_separator) {
|
||||
dest._path.pop_back();
|
||||
}
|
||||
@ -3277,6 +3282,7 @@ GHC_INLINE path path::lexically_normal() const
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(s.empty() && lastDotDot)) {
|
||||
dest /= s;
|
||||
}
|
||||
|
||||
@ -956,6 +956,9 @@ 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");
|
||||
CHECK(fs::path("./../foo/../../bar").lexically_normal() == "../../bar");
|
||||
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/");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user