about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <yuki.okushi@huawei.com>2021-11-16 14:36:20 +0900
committerYuki Okushi <yuki.okushi@huawei.com>2021-11-17 03:11:14 +0900
commitddc1d58ca83ab2c176929c47bd679cfbe8cf32f9 (patch)
treecfecfff5a6b3a0cbb73c78f8c176c3da4b15852d
parentb0535508474fb4353a3b83ef79df87817f028a71 (diff)
downloadrust-ddc1d58ca83ab2c176929c47bd679cfbe8cf32f9.tar.gz
rust-ddc1d58ca83ab2c176929c47bd679cfbe8cf32f9.zip
windows: Return the "Not Found" error when a path is empty
-rw-r--r--library/std/src/fs/tests.rs4
-rw-r--r--library/std/src/sys/windows/path.rs4
-rw-r--r--library/std/src/sys/windows/path/tests.rs3
3 files changed, 7 insertions, 4 deletions
diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs
index 628de13156c..112b292e6c1 100644
--- a/library/std/src/fs/tests.rs
+++ b/library/std/src/fs/tests.rs
@@ -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);
 }
diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs
index 460c1eff778..d0b7d9e7377 100644
--- a/library/std/src/sys/windows/path.rs
+++ b/library/std/src/sys/windows/path.rs
@@ -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.
diff --git a/library/std/src/sys/windows/path/tests.rs b/library/std/src/sys/windows/path/tests.rs
index c6c84519f41..425c2011b32 100644
--- a/library/std/src/sys/windows/path/tests.rs
+++ b/library/std/src/sys/windows/path/tests.rs
@@ -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());
 }