Skip to content

Commit c8b2529

Browse files
ChrisDentonpietroalbini
authored andcommitted
Restore old behaviour on broken UNC paths
1 parent f446c44 commit c8b2529

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,7 @@ fn parse_next_component(path: &OsStr, verbatim: bool) -> (&OsStr, &OsStr) {
198198

199199
match path.bytes().iter().position(|&x| separator(x)) {
200200
Some(separator_start) => {
201-
let mut separator_end = separator_start + 1;
202-
203-
// a series of multiple separator characters is treated as a single separator,
204-
// except in verbatim paths
205-
while !verbatim && separator_end < path.len() && separator(path.bytes()[separator_end])
206-
{
207-
separator_end += 1;
208-
}
201+
let separator_end = separator_start + 1;
209202

210203
let component = &path.bytes()[..separator_start];
211204

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ fn test_parse_next_component() {
3131
parse_next_component(OsStr::new(r"servershare"), false),
3232
(OsStr::new(r"servershare"), OsStr::new(""))
3333
);
34-
35-
assert_eq!(
36-
parse_next_component(OsStr::new(r"server/\//\/\\\\/////\/share"), false),
37-
(OsStr::new(r"server"), OsStr::new(r"share"))
38-
);
39-
40-
assert_eq!(
41-
parse_next_component(OsStr::new(r"server\\\\\\\\\\\\\\share"), true),
42-
(OsStr::new(r"server"), OsStr::new(r"\\\\\\\\\\\\\share"))
43-
);
4434
}
4535

4636
#[test]
@@ -126,3 +116,22 @@ fn test_windows_prefix_components() {
126116
assert_eq!(drive.as_os_str(), OsStr::new("C:"));
127117
assert_eq!(components.as_path(), Path::new(""));
128118
}
119+
120+
/// See #101358.
121+
///
122+
/// Note that the exact behaviour here may change in the future.
123+
/// In which case this test will need to adjusted.
124+
#[test]
125+
fn broken_unc_path() {
126+
use crate::path::Component;
127+
128+
let mut components = Path::new(r"\\foo\\bar\\").components();
129+
assert_eq!(components.next(), Some(Component::RootDir));
130+
assert_eq!(components.next(), Some(Component::Normal("foo".as_ref())));
131+
assert_eq!(components.next(), Some(Component::Normal("bar".as_ref())));
132+
133+
let mut components = Path::new("//foo//bar//").components();
134+
assert_eq!(components.next(), Some(Component::RootDir));
135+
assert_eq!(components.next(), Some(Component::Normal("foo".as_ref())));
136+
assert_eq!(components.next(), Some(Component::Normal("bar".as_ref())));
137+
}

0 commit comments

Comments
 (0)