Skip to content

Commit b918405

Browse files
committed
Add support for windows verbatim disk paths
1 parent 949a5b0 commit b918405

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result<Paths, PatternE
178178
#[cfg(windows)]
179179
fn check_windows_verbatim(p: &Path) -> bool {
180180
match p.components().next() {
181-
Some(Component::Prefix(ref p)) => p.kind().is_verbatim(),
181+
Some(Component::Prefix(ref p)) => {
182+
p.kind().is_verbatim() && !matches!(p.kind(), std::path::Prefix::VerbatimDisk(_))
183+
}
182184
_ => false,
183185
}
184186
}

tests/glob-std.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,25 @@ fn main() {
9191
)
9292
);
9393

94+
// std-canonicalized windows verbatim disk paths should work
95+
if env::consts::FAMILY == "windows" {
96+
let r_verbatim = PathBuf::from("r").canonicalize().unwrap();
97+
assert_eq!(
98+
glob_vec(&format!("{}\\**", r_verbatim.display().to_string()))
99+
.into_iter()
100+
.map(|p| p.strip_prefix(&r_verbatim).unwrap().to_owned())
101+
.collect::<Vec<_>>(),
102+
vec!(
103+
PathBuf::from("another"),
104+
PathBuf::from("one"),
105+
PathBuf::from("one\\another"),
106+
PathBuf::from("one\\another\\deep"),
107+
PathBuf::from("three"),
108+
PathBuf::from("two")
109+
)
110+
);
111+
}
112+
94113
// collapse consecutive recursive patterns
95114
assert_eq!(
96115
glob_vec("r/**/**"),

0 commit comments

Comments
 (0)