Skip to content

Commit

Permalink
literal: fix bug in TBM
Browse files Browse the repository at this point in the history
The TBM implementation tripped an assertion in debug mode if its
haystack was smaller than its query. This is incorrect. The correct
behavior is for TBM to report that no match can be found.

Fixes #437
  • Loading branch information
BurntSushi committed Dec 31, 2017
1 parent 6fe95dd commit e8e95bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ impl BoyerMooreSearch {
/// in `haystack`.
#[inline]
fn find(&self, haystack: &[u8]) -> Option<usize> {
debug_assert!(haystack.len() >= self.pattern.len());
if haystack.len() < self.pattern.len() {
return None;
}

let mut window_end = self.pattern.len() - 1;

Expand Down
7 changes: 7 additions & 0 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ ismatch!(strange_anchor_non_complete_suffix, r"${2}a", "", false);
// See: https://github.com/rust-lang/regex/issues/334
mat!(captures_after_dfa_premature_end, r"a(b*(X|$))?", "abcbX",
Some((0, 1)), None, None);

// See: https://github.com/rust-lang/regex/issues/437
ismatch!(
literal_panic,
r"typename type\-parameter\-\d+\-\d+::.+",
"test",
false);

0 comments on commit e8e95bb

Please sign in to comment.