Skip to content

Commit

Permalink
fix(vfs) Better handle path canonicalization on Windows.
Browse files Browse the repository at this point in the history
`C:\` is considered as a root, but we expect it to fail because we
don't accept such path as valid for the moment.
  • Loading branch information
Hywan committed Aug 30, 2021
1 parent dac47a8 commit e0a18a3
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions lib/vfs/src/mem_fs/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,17 +477,12 @@ impl FileSystemInner {
/// the path, which means that there is no guarantee that the path
/// exists in the file system.
pub(super) fn canonicalize_without_inode(&self, path: &Path) -> Result<PathBuf> {
if !path.has_root() {
return Err(FsError::InvalidInput);
}

let mut components = path.components();

assert_eq!(
components.next(),
Some(Component::RootDir),
"the root component is expected to be present",
);
match components.next() {
Some(Component::RootDir) => {}
_ => return Err(FsError::InvalidInput),
}

let mut new_path = PathBuf::with_capacity(path.as_os_str().len());
new_path.push("/");
Expand Down Expand Up @@ -1246,11 +1241,6 @@ mod test_filesystem {
Err(FsError::InvalidInput),
"canonicalizing `C:/foo/`",
);
assert_eq!(
fs_inner.canonicalize(path!("\\foo")),
Err(FsError::InvalidInput),
"canonicalizing `C:/foo/`",
);
assert_eq!(
fs_inner.canonicalize(path!(
"/foo/./../foo/bar/../../foo/bar/./baz/./../baz/qux/../../baz/./qux/hello.txt"
Expand Down

0 comments on commit e0a18a3

Please sign in to comment.