aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-04 11:57:50 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-04 11:57:50 -0600
commitf326eef2c9c827935a27de16748abe5e253b9979 (patch)
treebcf50f4ba7cb9616eb7b01b49b9d6b083ff31652 /src
parent680fca264f442bc91bf877115adc5010bc142229 (diff)
downloadmakers-f326eef2c9c827935a27de16748abe5e253b9979.tar.gz
makers-f326eef2c9c827935a27de16748abe5e253b9979.zip
force patterns to match full text
Diffstat (limited to 'src')
-rw-r--r--src/makefile/pattern.rs7
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(&regex::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(())
}
}