Show More
@@ -200,9 +200,11 b' pub fn build_single_regex(' | |||||
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().a |
|
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 | } | |
@@ -351,4 +353,20 b' mod tests {' | |||||
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 | } | |
|
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 | ); | |||
354 | } |
|
371 | } | |
|
372 | } |
General Comments 0
You need to be logged in to leave comments.
Login now