Skip to content

Commit

Permalink
regex/literal: fix bug in Boyer-Moore
Browse files Browse the repository at this point in the history
This patch fixes an issue where skip resolution would go strait
to the default value (the md2_shift) on a match failure after
the shift_loop. Now we do the right thing, and first check in
the skip table. The problem with going strait to the md2_shift
is that you can accidentally shift to far when `window_end`
actually is in the pattern (as is the case for the failing
match).
  • Loading branch information
ethanpailes authored and BurntSushi committed Mar 7, 2018
1 parent 43bb64b commit 7645ff2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ impl BoyerMooreSearch {
if self.check_match(haystack, window_end) {
return Some(window_end - (self.pattern.len() - 1));
} else {
window_end += self.md2_shift;
let skip = self.skip_table[haystack[window_end] as usize];
window_end +=
if skip == 0 { self.md2_shift } else { skip };
continue;
}
}
Expand Down Expand Up @@ -946,7 +948,6 @@ mod tests {
}

#[test]
#[should_panic]
fn bm_backstop_boundary() {
let haystack = b"\
// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Expand Down

0 comments on commit 7645ff2

Please sign in to comment.