Skip to content

Commit e3201da

Browse files
committed
lexically_relative: ignore trailing slash on base
Previously, fs::path("a/b").lexically_relative("a/") would incorrectly return "../b". Now it returns "b".
1 parent 26077f2 commit e3201da

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

include/ghc/filesystem.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ GHC_INLINE path path::lexically_relative(const path& base) const
26832683
}
26842684
int count = 0;
26852685
for (const auto& element : input_iterator_range<const_iterator>(b, base.end())) {
2686-
if (element != "." && element != "..") {
2686+
if (element != "." && element != "" && element != "..") {
26872687
++count;
26882688
}
26892689
else if (element == "..") {

test/filesystem_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ TEST_CASE("30.10.8.4.11 path generation", "[filesystem][path][fs.path.gen]")
882882
CHECK(fs::path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
883883
CHECK(fs::path("a/b/c").lexically_relative("a/b/c") == ".");
884884
CHECK(fs::path("a/b").lexically_relative("c/d") == "../../a/b");
885+
CHECK(fs::path("a/b").lexically_relative("a/") == "b");
885886
if (has_host_root_name_support()) {
886887
CHECK(fs::path("//host1/foo").lexically_relative("//host2.bar") == "");
887888
}

0 commit comments

Comments
 (0)