@@ -8,7 +8,7 @@ use crate::{
88 path:: { path_relative_from, AbsPath } ,
99} ;
1010use anyhow:: { anyhow, bail, ensure, Context , Result } ;
11- use glob:: Pattern ;
11+ use glob:: { MatchOptions , Pattern } ;
1212use log:: { debug, info} ;
1313
1414pub struct Linter {
@@ -23,7 +23,17 @@ pub struct Linter {
2323fn matches_relative_path ( base : & Path , from : & Path , pattern : & Pattern ) -> bool {
2424 // Unwrap ok because we already checked that both paths are absolute.
2525 let relative_path = path_relative_from ( from, base) . unwrap ( ) ;
26- pattern. matches ( relative_path. to_str ( ) . unwrap ( ) )
26+ pattern. matches_with (
27+ relative_path. to_str ( ) . unwrap ( ) ,
28+ MatchOptions {
29+ case_sensitive : true ,
30+ // Explicitly set this option to true. Most unix implementations do
31+ // not allow `*` to match across path segments, so the default
32+ // (false) behavior is unexpected for people.
33+ require_literal_separator : true ,
34+ require_literal_leading_dot : false ,
35+ } ,
36+ )
2737}
2838
2939impl Linter {
@@ -183,3 +193,21 @@ impl Linter {
183193 }
184194 }
185195}
196+
197+ #[ cfg( test) ]
198+ mod tests {
199+ use std:: path:: PathBuf ;
200+
201+ use super :: * ;
202+
203+ // Check that `*` does not match across path segments.
204+ #[ test]
205+ fn test_glob_with_separator ( ) -> Result < ( ) > {
206+ assert ! ( !matches_relative_path(
207+ & PathBuf :: from( "" ) ,
208+ & PathBuf :: from( "foo/bar/baz" ) ,
209+ & Pattern :: new( "foo/b*" ) ?,
210+ ) ) ;
211+ Ok ( ( ) )
212+ }
213+ }
0 commit comments