diff options
| author | bors <bors@rust-lang.org> | 2022-05-08 16:51:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-08 16:51:00 +0000 |
| commit | 83322c557fcaa9b6750955ceb6b9591df6c53a65 (patch) | |
| tree | 459720c5798f2fef11562412658f23475291dcdb | |
| parent | ed3164baf010592dda34da57c28fa8ae5e6c2ca6 (diff) | |
| parent | b87dd755ca8dd89ebb47a6f23c1c0fb656fe4d54 (diff) | |
| download | rust-83322c557fcaa9b6750955ceb6b9591df6c53a65.tar.gz rust-83322c557fcaa9b6750955ceb6b9591df6c53a65.zip | |
Auto merge of #93675 - name1e5s:fix/strip_prefix_panic, r=Mark-Simulacrum
fix panic in Path::strip_prefix close #93586
| -rw-r--r-- | library/std/src/path.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys/windows/path/tests.rs | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index c03d197e019..36d6469c02d 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -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), diff --git a/library/std/src/sys/windows/path/tests.rs b/library/std/src/sys/windows/path/tests.rs index 8656b04e4f4..2f7ec433bf2 100644 --- a/library/std/src/sys/windows/path/tests.rs +++ b/library/std/src/sys/windows/path/tests.rs @@ -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("")); +} |
