diff --git a/.agents/docs/testing-strategy.md b/.agents/docs/testing-strategy.md index e154ef3..6f60c02 100644 --- a/.agents/docs/testing-strategy.md +++ b/.agents/docs/testing-strategy.md @@ -35,7 +35,7 @@ The matrix is interaction-aware. A platform root kind must be crossed with encod - `try_relative` and `relative_with` assert borrowed descendant and equal suffixes, owned upward and dirty results, owned cwd-resolved results, and receiver-only borrowing when base and cwd are owned temporaries. - An independent public `relative_with` model resolves its own root and component structures without calling SugarPath or `std::path::components`, then checks 40,368 Unix and 161,472 Windows combinations across clean and dirty native spellings. Its dirty absolute cwd contains `..`; Unix comparison is exact, while Windows roots and components compare with ASCII case ignored. - On macOS and Linux, all 224,676 pairs from the bounded short absolute spelling set plus the multibyte set are checked through the production `relative_str` dispatch and the suffix-validation helper against the slow component oracle. -- Absolute paths with native-invalid normal components prove that equal raw encoding cancels and distinct encoding with the same lossy rendering does not, through `relative`, `try_relative`, and `relative_with` on Unix and Windows. +- Absolute paths with native-invalid normal components prove that equal raw encoding cancels and distinct encoding with the same lossy rendering does not, through `relative`, `try_relative`, and `relative_with` on Unix and Windows. Unix explicit-cwd rows also prove that relative resolution preserves native-invalid cwd components for borrowed and owned context arguments. - Unavailable Unix cwd coverage pins exact successful output and `Cow` variants for cwd-independent fallible calls, preserves the ambient error and panic checks for dependent `Path`, `str`, and `String` calls, and proves that a valid explicit cwd still succeeds. - Known-UTF-8 `str` and `String` receivers prove exact clean-trailing and dirty normalization contracts, receiver-only borrowing, explicit and ambient relative context forwarding, and cached-cwd behavior on Unix and Windows. Unix deleted-cwd rows also prove cwd-independent success and strict cwd-dependent panics for string receivers. diff --git a/tests/invalid_encoding.rs b/tests/invalid_encoding.rs index 962d123..34b3676 100644 --- a/tests/invalid_encoding.rs +++ b/tests/invalid_encoding.rs @@ -123,6 +123,21 @@ mod unix { assert_bytes(&absolute, b"/workspace/base-\x81/pkg/input-\x80/file"); } + + #[test] + fn relative_with_preserves_invalid_bytes_in_cwd() { + let cwd = path(b"/anchor/invalid-\x80/leaf"); + let target = Path::new("../target"); + let base = Path::new("../../base"); + + let borrowed_cwd = target.relative_with(base, cwd.as_path()); + assert_bytes(&borrowed_cwd, b"../invalid-\x80/target"); + assert!(matches!(borrowed_cwd, Cow::Owned(_))); + + let owned_cwd = target.relative_with(base, cwd); + assert_bytes(&owned_cwd, b"../invalid-\x80/target"); + assert!(matches!(owned_cwd, Cow::Owned(_))); + } } #[cfg(windows)]