diff options
Diffstat (limited to 'src/makefile/pattern.rs')
-rw-r--r-- | src/makefile/pattern.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/makefile/pattern.rs b/src/makefile/pattern.rs index b47c75d..9c5a0fa 100644 --- a/src/makefile/pattern.rs +++ b/src/makefile/pattern.rs @@ -2,7 +2,7 @@ use eyre::Result; use regex::{Captures, Regex}; fn compile_pattern(pattern: &str) -> Result<Regex> { - let mut result = String::new(); + let mut result = "^".to_owned(); for c in pattern.chars() { if c == '%' { if let Some(real_result) = result.strip_suffix(r"\\\\") { @@ -22,6 +22,7 @@ fn compile_pattern(pattern: &str) -> Result<Regex> { result.push_str(®ex::escape(&c.to_string())); } } + result.push('$'); Ok(Regex::new(&result)?) } @@ -38,10 +39,10 @@ mod test { #[test] fn pattern_backslashes() -> R { let test_case = compile_pattern(r"the\%weird\\%pattern\\")?; - assert_eq!(test_case.to_string(), r"the%weird\\(\w*)pattern\\\\"); + assert_eq!(test_case.to_string(), r"^the%weird\\(.*)pattern\\\\$"); let hell = compile_pattern(r"\\\\%")?; - assert_eq!(hell.to_string(), r"\\\\\\(\w*)"); + assert_eq!(hell.to_string(), r"^\\\\\\(.*)$"); Ok(()) } } |