From cf5188899b480d7318d254100ff312ac29619961 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Wed, 23 Oct 2019 22:21:10 +0200 Subject: [PATCH] refs #33, added test for trailing preferred seperator on last '..' for path::lexically_normal --- include/ghc/filesystem.hpp | 6 ++++++ test/filesystem_test.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 2397e75..ce2ca0e 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -2644,6 +2644,12 @@ GHC_INLINE path path::lexically_normal() const if (dest.empty()) { dest = "."; } + else { + static const path suffix[2] = {"", ".."}; + if(std::equal(std::reverse_iterator(dest.end()), std::reverse_iterator(dest.begin()), suffix)) { + dest._path.pop_back(); + } + } return dest; } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 939dce8..97c29a3 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -873,10 +873,12 @@ TEST_CASE("30.10.8.4.11 path generation", "[filesystem][path][fs.path.gen]") CHECK(fs::path("foo/..").lexically_normal() == "."); 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() == ".."); #ifdef GHC_OS_WINDOWS CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/"); CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/"); CHECK(fs::path("..a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/"); + CHECK(fs::path("..\\").lexically_normal() == ".."); #endif // lexically_relative()