Skip to content

Commit

Permalink
Merge pull request #112 from nico-abram/uwu
Browse files Browse the repository at this point in the history
Fixes #111
  • Loading branch information
JohnTitor authored Jan 11, 2023
2 parents 949a5b0 + 47c0cf3 commit 55d550e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ 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)) => {
// Allow VerbatimDisk paths. std canonicalize() generates them, and they work fine
p.kind().is_verbatim()
&& if let std::path::Prefix::VerbatimDisk(_) = p.kind() {
false
} else {
true
}
}
_ => 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 55d550e

Please sign in to comment.