Skip to content

Commit

Permalink
Auto merge of #93675 - name1e5s:fix/strip_prefix_panic, r=Mark-Simula…
Browse files Browse the repository at this point in the history
…crum

fix panic in Path::strip_prefix

close #93586
  • Loading branch information
bors committed May 8, 2022
2 parents ed3164b + b87dd75 commit 83322c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ impl<'a> Components<'a> {
if self.has_root() {
return false;
}
let mut iter = self.path[self.prefix_len()..].iter();
let mut iter = self.path[self.prefix_remaining()..].iter();
match (iter.next(), iter.next()) {
(Some(&b'.'), None) => true,
(Some(&b'.'), Some(&b)) => self.is_sep_byte(b),
Expand Down
12 changes: 12 additions & 0 deletions library/std/src/sys/windows/path/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,15 @@ fn test_parse_prefix_verbatim_device() {
assert_eq!(prefix, parse_prefix(r"/\?\C:\windows\system32\notepad.exe"));
assert_eq!(prefix, parse_prefix(r"\\?/C:\windows\system32\notepad.exe"));
}

// See #93586 for more infomation.
#[test]
fn test_windows_prefix_components() {
use crate::path::Path;

let path = Path::new("C:");
let mut components = path.components();
let drive = components.next().expect("drive is expected here");
assert_eq!(drive.as_os_str(), OsStr::new("C:"));
assert_eq!(components.as_path(), Path::new(""));
}

0 comments on commit 83322c5

Please sign in to comment.