From 831d54a21d8cfa399c698d1dd49171cf71f0c16a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schu=CC=88mann?= Date: Sun, 12 Jul 2026 00:00:06 +0200 Subject: [PATCH] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit a6aab92fb26c569d8fcf417d903601a3b3d4ce6f Author: Steffen Schümann Date: Sat Jul 11 23:04:57 2026 +0200 Refine `weakly_canonical` test to validate error codes and handle invalid paths more robustly. commit 21b931bd977608fcdcb1ae79aaf4383ffdae517c Merge: 48a868a 134f5e6 Author: Steffen Schümann Date: Sat Jul 11 22:11:16 2026 +0200 Merge branch 'master' into feature-204-weakly-canonical-ignores-errors commit 48a868a11a69ac174f9ec2eacc5ac78bd72b6ef3 Author: Steffen Schümann Date: Sat Jul 11 21:48:57 2026 +0200 Propagate `weakly_canonical()` component lookup errors and improve error handling in filesystem tests (#204) --- README.md | 2 ++ include/ghc/filesystem.hpp | 3 +-- test/filesystem_test.cpp | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7330593..0ec2099 100644 --- a/README.md +++ b/README.md @@ -659,6 +659,8 @@ to the expected behavior. `lexically_normal()` now preserves IPv6 components in device UNC paths. * Fix for [#171](https://github.com/gulrak/filesystem/issues/171), `canonical()` now supports device UNC paths. +* Fix for [#204](https://github.com/gulrak/filesystem/issues/204), + `weakly_canonical()` now propagates component lookup errors. * Fix for [#185](https://github.com/gulrak/filesystem/issues/185), `lexically_normal()` now preserves unresolved parent components in relative paths. diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 58f6ba8..454dfe7 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -5150,8 +5150,7 @@ GHC_INLINE path weakly_canonical(const path& p, std::error_code& ec) noexcept bool scan = true; for (auto pe : p) { if (scan) { - std::error_code tec; - if (exists(result / pe, tec)) { + if (exists(result / pe, ec)) { result /= pe; } else { diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 6761db2..263a837 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2862,6 +2862,24 @@ TEST_CASE("fs.op.weakly_canonical - weakly_canonical", "[filesystem][operations] CHECK(fs::weakly_canonical(rel / "d1/../f0") == dir / "f0"); CHECK(fs::weakly_canonical(rel / "d1/../f1") == dir / "f1"); CHECK(fs::weakly_canonical(rel / "d1/../f1/../f2") == dir / "f2"); + + std::error_code ec(42, std::system_category()); + CHECK(fs::weakly_canonical(dir / "missing/child", ec) == dir / "missing/child"); + CHECK(!ec); + + const auto invalid = dir / std::string(1024, 'x'); + std::error_code lookupError; + CHECK_FALSE(fs::exists(invalid, lookupError)); +#ifndef GHC_OS_WINDOWS + REQUIRE(lookupError); +#endif + if (lookupError) { + CHECK(fs::weakly_canonical(invalid, ec).empty()); + CHECK(ec == lookupError); +#ifdef GHC_WITH_EXCEPTIONS + CHECK_THROWS_AS(fs::weakly_canonical(invalid), fs::filesystem_error); +#endif + } } }