Skip to content

Commit

Permalink
Add support for windows verbatim disk paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-abram committed Jan 11, 2023
1 parent 949a5b0 commit b918405
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Result<Paths, PatternE
#[cfg(windows)]
fn check_windows_verbatim(p: &Path) -> bool {
match p.components().next() {
Some(Component::Prefix(ref p)) => p.kind().is_verbatim(),
Some(Component::Prefix(ref p)) => {
p.kind().is_verbatim() && !matches!(p.kind(), std::path::Prefix::VerbatimDisk(_))
}
_ => false,
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/glob-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ fn main() {
)
);

// std-canonicalized windows verbatim disk paths should work
if env::consts::FAMILY == "windows" {
let r_verbatim = PathBuf::from("r").canonicalize().unwrap();
assert_eq!(
glob_vec(&format!("{}\\**", r_verbatim.display().to_string()))
.into_iter()
.map(|p| p.strip_prefix(&r_verbatim).unwrap().to_owned())
.collect::<Vec<_>>(),
vec!(
PathBuf::from("another"),
PathBuf::from("one"),
PathBuf::from("one\\another"),
PathBuf::from("one\\another\\deep"),
PathBuf::from("three"),
PathBuf::from("two")
)
);
}

// collapse consecutive recursive patterns
assert_eq!(
glob_vec("r/**/**"),
Expand Down

0 comments on commit b918405

Please sign in to comment.