diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 8aa4167..1770d73 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -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(); } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 4a06c23..0be179f 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -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") == ".");