#[cfg(windows)]
use std::path::Path;
#[cfg(windows)]
#[test]
fn anchored_canonicalize_missing_backslash_regression() {
let tmp = tempfile::tempdir().unwrap();
let anchor = std::fs::canonicalize(tmp.path()).unwrap();
let candidate = Path::new("/data/dir");
let raw = soft_canonicalize::anchored_canonicalize(&anchor, candidate)
.expect("anchored canonicalize should succeed");
let s = raw.to_string_lossy();
let mut observed_bug = false;
if let Some(rest) = s.strip_prefix(r"\\?\") {
let b = rest.as_bytes();
if b.len() >= 3 && (b[0] as char).is_ascii_alphabetic() && b[1] == b':' {
if b[2] != b'\\' && b[2] != b'/' {
observed_bug = true;
}
}
}
assert!(
!observed_bug,
"soft-canonicalize::anchored_canonicalize returned malformed verbatim drive path: raw='{s}'"
);
let test_dir: crate::PathBoundary = crate::PathBoundary::try_new(tmp.path()).unwrap();
let anchored = crate::validator::path_history::PathHistory::new(candidate.to_path_buf())
.canonicalize_anchored(&test_dir)
.expect("normalized anchored canonicalize must succeed");
let fixed = anchored.to_string_lossy();
if let Some(rest) = fixed.strip_prefix(r"\\?\") {
let b = rest.as_bytes();
if b.len() >= 3 && (b[0] as char).is_ascii_alphabetic() && b[1] == b':' {
assert_eq!(
b[2], b'\\',
"normalized path must have backslash after drive colon: {fixed}"
);
}
}
}