From e5ae1bd3e395ad72eb8429ebc0475baf45808062 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Wed, 17 May 2023 07:18:52 +0200 Subject: [PATCH] refs #166, ".." does not have extension ." --- include/ghc/filesystem.hpp | 2 +- test/filesystem_test.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 53f4ad4..8e4573a 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3170,7 +3170,7 @@ GHC_INLINE path path::extension() const auto iter = end(); const auto& fn = *--iter; impl_string_type::size_type pos = fn._path.rfind('.'); - if (pos != std::string::npos && pos > 0) { + if (pos != std::string::npos && pos > 0 && fn._path != "..") { return path(fn._path.substr(pos), native_format); } } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 97af80c..4a06c23 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -817,6 +817,8 @@ TEST_CASE("fs.path.decompose - path decomposition", "[filesystem][path][fs.path. #else CHECK(fs::path("t:est.txt").stem() == "t:est"); #endif + CHECK(fs::path("/foo/.").stem() == "."); + CHECK(fs::path("/foo/..").stem() == ".."); // extension() CHECK(fs::path("/foo/bar.txt").extension() == ".txt"); @@ -825,6 +827,8 @@ TEST_CASE("fs.path.decompose - path decomposition", "[filesystem][path][fs.path. CHECK(fs::path(".bar").extension() == ""); CHECK(fs::path("..bar").extension() == ".bar"); CHECK(fs::path("t:est.txt").extension() == ".txt"); + CHECK(fs::path("/foo/.").extension() == ""); + CHECK(fs::path("/foo/..").extension() == ""); if (has_host_root_name_support()) { // //host-based root-names