Skip to content

Commit 83322c5

Browse files
committed
Auto merge of #93675 - name1e5s:fix/strip_prefix_panic, r=Mark-Simulacrum
fix panic in Path::strip_prefix close #93586
2 parents ed3164b + b87dd75 commit 83322c5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

library/std/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'a> Components<'a> {
725725
if self.has_root() {
726726
return false;
727727
}
728-
let mut iter = self.path[self.prefix_len()..].iter();
728+
let mut iter = self.path[self.prefix_remaining()..].iter();
729729
match (iter.next(), iter.next()) {
730730
(Some(&b'.'), None) => true,
731731
(Some(&b'.'), Some(&b)) => self.is_sep_byte(b),

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

+12
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@ fn test_parse_prefix_verbatim_device() {
114114
assert_eq!(prefix, parse_prefix(r"/\?\C:\windows\system32\notepad.exe"));
115115
assert_eq!(prefix, parse_prefix(r"\\?/C:\windows\system32\notepad.exe"));
116116
}
117+
118+
// See #93586 for more infomation.
119+
#[test]
120+
fn test_windows_prefix_components() {
121+
use crate::path::Path;
122+
123+
let path = Path::new("C:");
124+
let mut components = path.components();
125+
let drive = components.next().expect("drive is expected here");
126+
assert_eq!(drive.as_os_str(), OsStr::new("C:"));
127+
assert_eq!(components.as_path(), Path::new(""));
128+
}

0 commit comments

Comments
 (0)