@@ -40,8 +40,8 @@ impl GlobPatterns {
4040 self . patterns . is_empty ( )
4141 }
4242
43- pub ( crate ) fn is_match ( & self , value : & str ) -> bool {
44- self . set . is_match ( Path :: new ( value ) )
43+ pub ( crate ) fn is_match ( & self , path : & Path ) -> bool {
44+ self . set . is_match ( path )
4545 }
4646}
4747
@@ -182,19 +182,22 @@ pub(crate) enum FilePattern {
182182}
183183
184184impl FilePattern {
185- pub ( crate ) fn new_glob ( patterns : Vec < String > ) -> Result < Self , globset:: Error > {
185+ pub ( crate ) fn glob ( patterns : Vec < String > ) -> Result < Self , globset:: Error > {
186186 Ok ( Self :: Glob ( GlobPatterns :: new ( patterns) ?) )
187187 }
188188
189- pub ( crate ) fn new_regex ( pattern : & str ) -> Result < Self , fancy_regex:: Error > {
189+ pub ( crate ) fn regex ( pattern : & str ) -> Result < Self , fancy_regex:: Error > {
190190 Ok ( Self :: Regex ( Regex :: new ( pattern) ?) )
191191 }
192192
193- pub ( crate ) fn is_match ( & self , str : & str ) -> bool {
193+ pub ( crate ) fn is_match ( & self , path : & Path ) -> bool {
194194 match self {
195195 FilePattern :: Never => false ,
196- FilePattern :: Regex ( regex) => regex. is_match ( str) . unwrap_or ( false ) ,
197- FilePattern :: Glob ( globs) => globs. is_match ( str) ,
196+ // Regex patterns are text matchers; globs can match OS paths directly.
197+ FilePattern :: Regex ( regex) => path
198+ . to_str ( )
199+ . is_some_and ( |path| regex. is_match ( path) . unwrap_or ( false ) ) ,
200+ FilePattern :: Glob ( globs) => globs. is_match ( path) ,
198201 }
199202 }
200203}
@@ -1460,9 +1463,9 @@ mod tests {
14601463 matches!( parsed. files, FilePattern :: Regex ( _) ) ,
14611464 "expected regex pattern"
14621465 ) ;
1463- assert ! ( parsed. files. is_match( "src/main.rs" ) ) ;
1464- assert ! ( !parsed. files. is_match( "other/main.rs" ) ) ;
1465- assert ! ( parsed. exclude. is_match( "target/debug/app" ) ) ;
1466+ assert ! ( parsed. files. is_match( Path :: new ( "src/main.rs" ) ) ) ;
1467+ assert ! ( !parsed. files. is_match( Path :: new ( "other/main.rs" ) ) ) ;
1468+ assert ! ( parsed. exclude. is_match( Path :: new ( "target/debug/app" ) ) ) ;
14661469
14671470 let glob_yaml = indoc:: indoc! { r"
14681471 files:
@@ -1476,10 +1479,10 @@ mod tests {
14761479 matches!( parsed. files, FilePattern :: Glob ( _) ) ,
14771480 "expected glob pattern"
14781481 ) ;
1479- assert ! ( parsed. files. is_match( "src/lib/main.rs" ) ) ;
1480- assert ! ( !parsed. files. is_match( "src/lib/main.py" ) ) ;
1481- assert ! ( parsed. exclude. is_match( "target/debug/app" ) ) ;
1482- assert ! ( !parsed. exclude. is_match( "src/lib/main.rs" ) ) ;
1482+ assert ! ( parsed. files. is_match( Path :: new ( "src/lib/main.rs" ) ) ) ;
1483+ assert ! ( !parsed. files. is_match( Path :: new ( "src/lib/main.py" ) ) ) ;
1484+ assert ! ( parsed. exclude. is_match( Path :: new ( "target/debug/app" ) ) ) ;
1485+ assert ! ( !parsed. exclude. is_match( Path :: new ( "src/lib/main.rs" ) ) ) ;
14831486
14841487 let glob_list_yaml = indoc:: indoc! { r"
14851488 files:
@@ -1493,11 +1496,11 @@ mod tests {
14931496 " } ;
14941497 let parsed: Wrapper =
14951498 serde_saphyr:: from_str ( glob_list_yaml) . expect ( "glob list patterns should parse" ) ;
1496- assert ! ( parsed. files. is_match( "src/lib/main.rs" ) ) ;
1497- assert ! ( parsed. files. is_match( "crates/foo/src/lib.rs" ) ) ;
1498- assert ! ( !parsed. files. is_match( "tests/main.rs" ) ) ;
1499- assert ! ( parsed. exclude. is_match( "target/debug/app" ) ) ;
1500- assert ! ( parsed. exclude. is_match( "dist/app" ) ) ;
1499+ assert ! ( parsed. files. is_match( Path :: new ( "src/lib/main.rs" ) ) ) ;
1500+ assert ! ( parsed. files. is_match( Path :: new ( "crates/foo/src/lib.rs" ) ) ) ;
1501+ assert ! ( !parsed. files. is_match( Path :: new ( "tests/main.rs" ) ) ) ;
1502+ assert ! ( parsed. exclude. is_match( Path :: new ( "target/debug/app" ) ) ) ;
1503+ assert ! ( parsed. exclude. is_match( Path :: new ( "dist/app" ) ) ) ;
15011504 }
15021505
15031506 #[ test]
@@ -1512,24 +1515,24 @@ mod tests {
15121515 pattern. to_string( ) ,
15131516 "glob: [src/**/*.rs, crates/**/src/**/*.rs]"
15141517 ) ;
1515- assert ! ( pattern. is_match( "src/main.rs" ) ) ;
1516- assert ! ( pattern. is_match( "crates/foo/src/lib.rs" ) ) ;
1517- assert ! ( !pattern. is_match( "tests/main.rs" ) ) ;
1518+ assert ! ( pattern. is_match( Path :: new ( "src/main.rs" ) ) ) ;
1519+ assert ! ( pattern. is_match( Path :: new ( "crates/foo/src/lib.rs" ) ) ) ;
1520+ assert ! ( !pattern. is_match( Path :: new ( "tests/main.rs" ) ) ) ;
15181521 }
15191522
15201523 #[ test]
15211524 fn file_pattern_never_matches ( ) {
15221525 let pattern = FilePattern :: Never ;
1523- assert ! ( !pattern. is_match( "" ) ) ;
1524- assert ! ( !pattern. is_match( "foo.txt" ) ) ;
1525- assert ! ( !pattern. is_match( "nested/path.rs" ) ) ;
1526+ assert ! ( !pattern. is_match( Path :: new ( "" ) ) ) ;
1527+ assert ! ( !pattern. is_match( Path :: new ( "foo.txt" ) ) ) ;
1528+ assert ! ( !pattern. is_match( Path :: new ( "nested/path.rs" ) ) ) ;
15261529 }
15271530
15281531 #[ test]
15291532 fn empty_glob_list_matches_nothing ( ) {
15301533 let pattern = serde_saphyr:: from_str :: < FilePattern > ( "glob: []" ) . unwrap ( ) ;
1531- assert ! ( !pattern. is_match( "any/file.rs" ) ) ;
1532- assert ! ( !pattern. is_match( "" ) ) ;
1534+ assert ! ( !pattern. is_match( Path :: new ( "any/file.rs" ) ) ) ;
1535+ assert ! ( !pattern. is_match( Path :: new ( "" ) ) ) ;
15331536 }
15341537
15351538 #[ test]
0 commit comments