Squashed commit of the following:

commit a6aab92fb26c569d8fcf417d903601a3b3d4ce6f
Author: Steffen Schümann <s.schuemann@pobox.com>
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 <s.schuemann@pobox.com>
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 <s.schuemann@pobox.com>
Date:   Sat Jul 11 21:48:57 2026 +0200

    Propagate `weakly_canonical()` component lookup errors and improve error handling in filesystem tests (#204)
This commit is contained in:
Steffen Schümann 2026-07-12 00:00:06 +02:00
parent 134f5e61be
commit 831d54a21d
3 changed files with 21 additions and 2 deletions

View File

@ -659,6 +659,8 @@ to the expected behavior.
`lexically_normal()` now preserves IPv6 components in device UNC paths. `lexically_normal()` now preserves IPv6 components in device UNC paths.
* Fix for [#171](https://github.com/gulrak/filesystem/issues/171), `canonical()` * Fix for [#171](https://github.com/gulrak/filesystem/issues/171), `canonical()`
now supports device UNC paths. 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), * Fix for [#185](https://github.com/gulrak/filesystem/issues/185),
`lexically_normal()` now preserves unresolved parent components in relative `lexically_normal()` now preserves unresolved parent components in relative
paths. paths.

View File

@ -5150,8 +5150,7 @@ GHC_INLINE path weakly_canonical(const path& p, std::error_code& ec) noexcept
bool scan = true; bool scan = true;
for (auto pe : p) { for (auto pe : p) {
if (scan) { if (scan) {
std::error_code tec; if (exists(result / pe, ec)) {
if (exists(result / pe, tec)) {
result /= pe; result /= pe;
} }
else { else {

View File

@ -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/../f0") == dir / "f0");
CHECK(fs::weakly_canonical(rel / "d1/../f1") == dir / "f1"); CHECK(fs::weakly_canonical(rel / "d1/../f1") == dir / "f1");
CHECK(fs::weakly_canonical(rel / "d1/../f1/../f2") == dir / "f2"); 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
}
} }
} }