From e3201da883e2ba8f0b07107946c46c67b7e0e779 Mon Sep 17 00:00:00 2001 From: Michael M Date: Sun, 22 Mar 2020 16:26:59 -0700 Subject: [PATCH] lexically_relative: ignore trailing slash on base Previously, fs::path("a/b").lexically_relative("a/") would incorrectly return "../b". Now it returns "b". --- include/ghc/filesystem.hpp | 2 +- test/filesystem_test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 7951369..60381f3 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -2683,7 +2683,7 @@ GHC_INLINE path path::lexically_relative(const path& base) const } int count = 0; for (const auto& element : input_iterator_range(b, base.end())) { - if (element != "." && element != "..") { + if (element != "." && element != "" && element != "..") { ++count; } else if (element == "..") { diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index ffaa0c6..8e21369 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -882,6 +882,7 @@ TEST_CASE("30.10.8.4.11 path generation", "[filesystem][path][fs.path.gen]") CHECK(fs::path("a/b/c").lexically_relative("a/b/c/x/y") == "../.."); CHECK(fs::path("a/b/c").lexically_relative("a/b/c") == "."); CHECK(fs::path("a/b").lexically_relative("c/d") == "../../a/b"); + CHECK(fs::path("a/b").lexically_relative("a/") == "b"); if (has_host_root_name_support()) { CHECK(fs::path("//host1/foo").lexically_relative("//host2.bar") == ""); }