Fix windows verbatim paths (#1295)

This commit is contained in:
EgoMoose
2026-07-05 14:26:35 -04:00
committed by GitHub
parent 0289491ccb
commit 7ade19293c
8 changed files with 93 additions and 4 deletions

View File

@@ -644,13 +644,49 @@ mod test {
let vfs = Vfs::new(StdBackend::new().unwrap());
let canonicalized = vfs.canonicalize(&file_path).unwrap();
assert_eq!(canonicalized, file_path.canonicalize().unwrap());
assert_eq!(canonicalized, dunce::canonicalize(&file_path).unwrap());
assert_eq!(
vfs.read_to_string(&canonicalized).unwrap().to_string(),
contents.to_string()
);
}
#[test]
#[cfg(windows)]
fn canonicalize_std_backend_not_verbatim() {
use std::path::{Component, Prefix};
let dir = tempfile::tempdir().unwrap();
let file_path = dir.path().join("file.txt");
fs_err::write(&file_path, "hello").unwrap();
let vfs = Vfs::new(StdBackend::new().unwrap());
let canonicalized = vfs.canonicalize(&file_path).unwrap();
let is_verbatim = matches!(
canonicalized.components().next(),
Some(Component::Prefix(prefix)) if matches!(
prefix.kind(),
Prefix::Verbatim(_) | Prefix::VerbatimDisk(_) | Prefix::VerbatimUNC(_, _)
)
);
assert!(
!is_verbatim,
"expected a non-verbatim path, got {:?}",
canonicalized
);
// Joining a relative parent path must preserve the `..` segment. On a
// verbatim path Rust would drop it lexically, which is the root cause
// of the bug.
let joined = canonicalized.join("..").join("sibling");
assert!(
joined.components().any(|c| c == Component::ParentDir),
"`..` should be preserved when joining onto {:?}",
canonicalized
);
}
#[test]
fn canonicalize_std_backend_missing_errors() {
let dir = tempfile::tempdir().unwrap();

View File

@@ -107,7 +107,7 @@ impl VfsBackend for StdBackend {
}
fn canonicalize(&mut self, path: &Path) -> io::Result<PathBuf> {
fs_err::canonicalize(path)
dunce::canonicalize(path)
}
fn event_receiver(&self) -> crossbeam_channel::Receiver<VfsEvent> {