diff --git a/src/exec.rs b/src/exec.rs index d5d3bf3f7a..68a9e18f43 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -850,9 +850,12 @@ impl<'c> ExecNoSync<'c> { match_start: usize, match_end: usize, ) -> Option<(usize, usize)> { - // We can't use match_end directly, because we may need to examine - // one "character" after the end of a match for lookahead operators. - let e = cmp::min(next_utf8(text, match_end), text.len()); + // We can't use match_end directly, because we may need to examine one + // "character" after the end of a match for lookahead operators. We + // need to move two characters beyond the end, since some look-around + // operations may falsely assume a premature end of text otherwise. + let e = cmp::min( + next_utf8(text, next_utf8(text, match_end)), text.len()); self.captures_nfa(slots, &text[..e], match_start) } diff --git a/tests/regression.rs b/tests/regression.rs index 1feeda17cb..7a30b1527f 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -86,3 +86,7 @@ mat!(wb_start_x, r"(?u:\b)^(?-u:X)", "X", Some((0, 1))); // See: https://github.com/rust-lang/regex/issues/321 ismatch!(strange_anchor_non_complete_prefix, r"a^{2}", "", false); 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);