diff --git a/src/lib.rs b/src/lib.rs index 314c078..801ed91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -878,6 +878,9 @@ fn fill_todo( }); match dirs { Ok(mut children) => { + if options.require_literal_leading_dot { + children.retain(|x| !x.file_name().unwrap().to_str().unwrap().starts_with(".")); + } children.sort_by(|p1, p2| p2.file_name().cmp(&p1.file_name())); todo.extend(children.into_iter().map(|x| Ok((x, idx)))); diff --git a/tests/glob-std.rs b/tests/glob-std.rs index 085eb6d..a96f725 100644 --- a/tests/glob-std.rs +++ b/tests/glob-std.rs @@ -15,7 +15,7 @@ extern crate glob; extern crate tempdir; -use glob::glob; +use glob::{glob, glob_with}; use std::env; use std::fs; use std::path::PathBuf; @@ -35,6 +35,10 @@ fn main() { glob(pattern).unwrap().map(|r| r.unwrap()).collect() } + fn glob_with_vec(pattern: &str, options: glob::MatchOptions) -> Vec { + glob_with(pattern, options).unwrap().map(|r| r.unwrap()).collect() + } + let root = TempDir::new("glob-tests"); let root = root.ok().expect("Should have created a temp directory"); assert!(env::set_current_dir(root.path()).is_ok()); @@ -288,6 +292,27 @@ fn main() { vec!(PathBuf::from("bbb/specials/]")) ); + mk_file("i", true); + mk_file("i/qwe", true); + mk_file("i/qwe/.aaa", false); + mk_file("i/qwe/.bbb", true); + mk_file("i/qwe/.bbb/ccc", false); + mk_file("i/qwe/.bbb/.ddd", false); + mk_file("i/qwe/eee", false); + + let options = glob::MatchOptions { + case_sensitive: false, + require_literal_separator: true, + require_literal_leading_dot: true, + }; + assert_eq!(glob_with_vec("i/**/*a*", options), Vec::::new()); + assert_eq!(glob_with_vec("i/**/*c*", options), Vec::::new()); + assert_eq!(glob_with_vec("i/**/*d*", options), Vec::::new()); + assert_eq!( + glob_with_vec("i/**/*e*", options), + vec!(PathBuf::from("i/qwe"), PathBuf::from("i/qwe/eee")) + ); + if env::consts::FAMILY != "windows" { assert_eq!( glob_vec("bbb/specials/[*]"),