From 7fed69565a01ca716fcdb01082e23d29099052cd Mon Sep 17 00:00:00 2001 From: nino-exe <173394600+nino-exe@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:20:37 +0200 Subject: [PATCH] policy: resolve a `..` in the not-yet-existing part of a path `resolve` canonicalizes the longest existing prefix and re-appends the rest, but it walks up with `Path::file_name()`, which is None for a trailing `..`. A path such as `/a/../b` (nothing exists yet) hit the `_` arm and returned PolicyError::Io, so a cache_dir or data_dir with a `..` in a directory that does not exist yet was rejected, and `normalize`'s `..` handling for the missing tail was never reached. A trailing `..` is now kept in `rest` so `normalize` resolves it lexically. Test: resolves_dot_dot_in_a_path_that_does_not_exist_yet (fails before, passes after). cargo test -p victory-core, cargo fmt --check and cargo clippy --tests are clean. (cherry picked from commit 52f0a099ede8aa4d5bde61a0c46963a77a4378ba) --- crates/victory-core/src/policy.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/victory-core/src/policy.rs b/crates/victory-core/src/policy.rs index b10e1c6..d49acc4 100644 --- a/crates/victory-core/src/policy.rs +++ b/crates/victory-core/src/policy.rs @@ -92,6 +92,11 @@ fn resolve(path: &Path) -> Result { rest.push(name.to_os_string()); existing = parent; } + // `file_name()` is None for a trailing `..`; keep it so `normalize` resolves it. + (Some(parent), None) if existing.ends_with("..") => { + rest.push("..".into()); + existing = parent; + } _ => { return Err(PolicyError::Io { path: path.to_path_buf(), @@ -156,4 +161,12 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); ensure_outside_repo(&tmp.path().join("does").join("not").join("exist")).unwrap(); } + + #[test] + fn resolves_dot_dot_in_a_path_that_does_not_exist_yet() { + let base = std::env::temp_dir().join("victory-policy-no-such"); + let path = base.join("a").join("..").join("b"); + let resolved = resolve(&path).expect("a `..` in the missing tail must resolve lexically"); + assert_eq!(resolved, resolve(&base.join("b")).unwrap()); + } }