equal
deleted
inserted
replaced
198 pat: &[u8], |
198 pat: &[u8], |
199 globsuffix: &[u8], |
199 globsuffix: &[u8], |
200 ) -> Result<Vec<u8>, PatternError> { |
200 ) -> Result<Vec<u8>, PatternError> { |
201 let enum_kind = parse_pattern_syntax(kind)?; |
201 let enum_kind = parse_pattern_syntax(kind)?; |
202 if enum_kind == PatternSyntax::RootGlob |
202 if enum_kind == PatternSyntax::RootGlob |
203 && pat.iter().all(|b| GLOB_SPECIAL_CHARACTERS.contains(b)) |
203 && !pat.iter().any(|b| GLOB_SPECIAL_CHARACTERS.contains(b)) |
204 { |
204 { |
205 Ok(pat.to_vec()) |
205 let mut escaped = escape_pattern(pat); |
|
206 escaped.extend(b"(?:/|$)"); |
|
207 Ok(escaped) |
206 } else { |
208 } else { |
207 Ok(_build_single_regex(enum_kind, pat, globsuffix)) |
209 Ok(_build_single_regex(enum_kind, pat, globsuffix)) |
208 } |
210 } |
209 } |
211 } |
210 |
212 |
349 assert_eq!( |
351 assert_eq!( |
350 parse_pattern_file_contents(lines, b"file_path", false).0, |
352 parse_pattern_file_contents(lines, b"file_path", false).0, |
351 vec![(b"relglob:**.o".to_vec(), 1, b"**.o".to_vec())] |
353 vec![(b"relglob:**.o".to_vec(), 1, b"**.o".to_vec())] |
352 ); |
354 ); |
353 } |
355 } |
354 } |
356 |
|
357 #[test] |
|
358 fn test_build_single_regex_shortcut() { |
|
359 assert_eq!( |
|
360 br"(?:/|$)".to_vec(), |
|
361 build_single_regex(b"rootglob", b"", b"").unwrap() |
|
362 ); |
|
363 assert_eq!( |
|
364 br"whatever(?:/|$)".to_vec(), |
|
365 build_single_regex(b"rootglob", b"whatever", b"").unwrap() |
|
366 ); |
|
367 assert_eq!( |
|
368 br"[^/]*\.o".to_vec(), |
|
369 build_single_regex(b"rootglob", b"*.o", b"").unwrap() |
|
370 ); |
|
371 } |
|
372 } |