Skip to content

Commit

Permalink
Merge pull request #179 from vgeorgiev/lexically_relative_fix
Browse files Browse the repository at this point in the history
Fix lexically_relative return when base path evaluates to *this
  • Loading branch information
gulrak committed Feb 29, 2024
2 parents 2fc4b46 + eeed314 commit 42ea4fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3306,6 +3306,9 @@ GHC_INLINE path path::lexically_relative(const path& base) const
--count;
}
}
if (count == 0 && (a == end() || a->empty())) {
return path(".");
}
if (count < 0) {
return path();
}
Expand Down
4 changes: 4 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ TEST_CASE("fs.path.gen - path generation", "[filesystem][path][fs.path.gen]")
// lexically_relative()
CHECK(fs::path("/a/d").lexically_relative("/a/b/c") == "../../d");
CHECK(fs::path("/a/b/c").lexically_relative("/a/d") == "../b/c");
CHECK(fs::path("/a/b/c").lexically_relative("/a/b/c/d/..") == ".");
CHECK(fs::path("/a/b/c/").lexically_relative("/a/b/c/d/..") == ".");
CHECK(fs::path("").lexically_relative("/a/..") == "");
CHECK(fs::path("").lexically_relative("a/..") == ".");
CHECK(fs::path("a/b/c").lexically_relative("a") == "b/c");
CHECK(fs::path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
CHECK(fs::path("a/b/c").lexically_relative("a/b/c") == ".");
Expand Down

0 comments on commit 42ea4fc

Please sign in to comment.