Skip to content

Commit

Permalink
Check for unescaped trailing \ when reparsing a MultiPattern
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrutar committed Dec 9, 2024
1 parent d17e29a commit 387b17c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ impl MultiPattern {
let old_status = self.cols[column].1;
if append
&& old_status != Status::Rescore
&& self.cols[column]
.0
.atoms
.last()
.map_or(true, |last| !last.negative)
// must be rescored if the atom is negative or if there is an unescaped
// trailing `\`
&& self.cols[column].0.atoms.last().map_or(true, |last| {
!last.negative
&& last
.needle_text()
.chars()
.rev()
.take_while(|c| *c == '\\')
.count()
% 2
== 0
})
{
self.cols[column].1 = Status::Update;
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/pattern/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,24 @@ fn append() {
assert_eq!(pat.status(), Status::Update);
pat.reparse(0, "!fo", CaseMatching::Smart, Normalization::Smart, true);
assert_eq!(pat.status(), Status::Rescore);

let mut pat = MultiPattern::new(1);
pat.reparse(0, "a\\\\", CaseMatching::Smart, Normalization::Smart, true);
assert_eq!(pat.status(), Status::Update);
pat.reparse(
0,
"a\\\\\\",
CaseMatching::Smart,
Normalization::Smart,
true,
);
assert_eq!(pat.status(), Status::Update);
pat.reparse(
0,
"a\\\\\\\\",
CaseMatching::Smart,
Normalization::Smart,
true,
);
assert_eq!(pat.status(), Status::Rescore);
}

0 comments on commit 387b17c

Please sign in to comment.