Skip to content

Commit e8e95bb

Browse files
committed
literal: fix bug in TBM
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
1 parent 6fe95dd commit e8e95bb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/literals.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ impl BoyerMooreSearch {
599599
/// in `haystack`.
600600
#[inline]
601601
fn find(&self, haystack: &[u8]) -> Option<usize> {
602-
debug_assert!(haystack.len() >= self.pattern.len());
602+
if haystack.len() < self.pattern.len() {
603+
return None;
604+
}
603605

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

tests/regression.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ ismatch!(strange_anchor_non_complete_suffix, r"${2}a", "", false);
9090
// See: https://github.com/rust-lang/regex/issues/334
9191
mat!(captures_after_dfa_premature_end, r"a(b*(X|$))?", "abcbX",
9292
Some((0, 1)), None, None);
93+
94+
// See: https://github.com/rust-lang/regex/issues/437
95+
ismatch!(
96+
literal_panic,
97+
r"typename type\-parameter\-\d+\-\d+::.+",
98+
"test",
99+
false);

0 commit comments

Comments
 (0)