Skip to content

Commit ddc1d58

Browse files
committed
windows: Return the "Not Found" error when a path is empty
1 parent b053550 commit ddc1d58

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

library/std/src/fs/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1439,4 +1439,8 @@ fn create_dir_long_paths() {
14391439
// This will fail if the path isn't converted to verbatim.
14401440
path.push("a");
14411441
fs::create_dir(&path).unwrap();
1442+
1443+
// #90940: Ensure an empty path returns the "Not Found" error.
1444+
let path = Path::new("");
1445+
assert_eq!(path.canonicalize().unwrap_err().kind(), crate::io::ErrorKind::NotFound);
14421446
}

library/std/src/sys/windows/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ pub(crate) fn maybe_verbatim(path: &Path) -> io::Result<Vec<u16>> {
174174
const UNC_PREFIX: &[u16] = &[SEP, SEP, QUERY, SEP, U, N, C, SEP];
175175

176176
let mut path = to_u16s(path)?;
177-
if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) {
178-
// Early return for paths that are already verbatim.
177+
if path.starts_with(VERBATIM_PREFIX) || path.starts_with(NT_PREFIX) || path == &[0] {
178+
// Early return for paths that are already verbatim or empty.
179179
return Ok(path);
180180
} else if path.len() < LEGACY_MAX_PATH {
181181
// Early return if an absolute path is less < 260 UTF-16 code units.

library/std/src/sys/windows/path/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ fn verbatim() {
9191
// Make sure opening a drive will work.
9292
check("Z:", "Z:");
9393

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

0 commit comments

Comments
 (0)