Skip to content

Commit

Permalink
windows: Return the "Not Found" error when a path is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Nov 16, 2021
1 parent b053550 commit ddc1d58
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions library/std/src/fs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,4 +1439,8 @@ fn create_dir_long_paths() {
// This will fail if the path isn't converted to verbatim.
path.push("a");
fs::create_dir(&path).unwrap();

// #90940: Ensure an empty path returns the "Not Found" error.
let path = Path::new("");
assert_eq!(path.canonicalize().unwrap_err().kind(), crate::io::ErrorKind::NotFound);
}
4 changes: 2 additions & 2 deletions library/std/src/sys/windows/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub(crate) fn maybe_verbatim(path: &Path) -> io::Result<Vec<u16>> {
const UNC_PREFIX: &[u16] = &[SEP, SEP, QUERY, SEP, U, N, C, SEP];

let mut path = to_u16s(path)?;
if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) {
// Early return for paths that are already verbatim.
if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) || path == &[0] {
// Early return for paths that are already verbatim or empty.
return Ok(path);
} else if path.len() < LEGACY_MAX_PATH {
// Early return if an absolute path is less < 260 UTF-16 code units.
Expand Down
3 changes: 1 addition & 2 deletions library/std/src/sys/windows/path/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fn verbatim() {
// Make sure opening a drive will work.
check("Z:", "Z:");

// An empty path or a path that contains null are not valid paths.
assert!(maybe_verbatim(Path::new("")).is_err());
// A path that contains null is not a valid path.
assert!(maybe_verbatim(Path::new("\0")).is_err());
}

0 comments on commit ddc1d58

Please sign in to comment.