Skip to content

Commit f62984f

Browse files
authored
Rollup merge of #90942 - JohnTitor:should-os-error-3, r=m-ou-se
windows: Return the "Not Found" error when a path is empty Fixes #90940
2 parents b542224 + ddc1d58 commit f62984f

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
@@ -1430,4 +1430,8 @@ fn create_dir_long_paths() {
14301430
// This will fail if the path isn't converted to verbatim.
14311431
path.push("a");
14321432
fs::create_dir(&path).unwrap();
1433+
1434+
// #90940: Ensure an empty path returns the "Not Found" error.
1435+
let path = Path::new("");
1436+
assert_eq!(path.canonicalize().unwrap_err().kind(), crate::io::ErrorKind::NotFound);
14331437
}

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)