Skip to content

Commit

Permalink
Fix pattern error reporting bug.
Browse files Browse the repository at this point in the history
When using the `..~` operator, it could eventually match after having
failed several times, and accidentally increment the apparent line the
pattern failed to match at. This didn't affect the matching algorithm,
but meant that a failure to match would report the wrong position in the
pattern. The new test line below incorrectly reported `(8, 6)` before
the fix in this commit.
  • Loading branch information
ltratt committed Jun 3, 2024
1 parent bf4cf6c commit ba7da28
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl<'a> FMatcher<'a> {
// pattern, but advance the text.
ptn_lines_sub = ptn_lines.clone();
ptnl_sub = ptnl;
ptn_lines_off_sub += 1;
ptn_lines_off_sub = ptn_lines_off_orig;
textl_sub = text_lines.next();
text_lines_off += 1;
text_lines_sub = text_lines.clone();
Expand Down Expand Up @@ -1018,6 +1018,7 @@ mod tests {
assert_eq!(helper("a\n..~\nc\nd\ne", "a\nb\nc\nd"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nb\nc\ne"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nc\ne\nc\ne"), (2, 2));
assert_eq!(helper("a\n..~\nc\nd\n...\nf", "a\ne\nf\nc\nd\ne"), (5, 6));
}

#[test]
Expand Down

0 comments on commit ba7da28

Please sign in to comment.