diff --git a/regexec.c b/regexec.c index e8035462eab20a..56e3ab8967d367 100644 --- a/regexec.c +++ b/regexec.c @@ -3758,14 +3758,15 @@ match_at(regex_t* reg, const UChar* str, const UChar* end, CASE(OP_PUSH_IF_PEEK_NEXT) MOP_IN(OP_PUSH_IF_PEEK_NEXT); GET_RELADDR_INC(addr, p); + CHECK_MATCH_CACHE; if (*p == *s) { p++; - CHECK_MATCH_CACHE; STACK_PUSH_ALT(p + addr, s, sprev, pkeep); MOP_OUT; JUMP; } p++; + INC_NUM_FAILS; MOP_OUT; JUMP; diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 6973e21c7aa24a..e04794263724bc 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1945,6 +1945,15 @@ def test_match_cache_negative_look_behind end; end + def test_match_cache_with_peek_optimization + assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") + timeout = #{ EnvUtil.apply_timeout_scale(10).inspect } + begin; + Regexp.timeout = timeout + assert_nil(/a*z/ =~ "a" * 1000000 + "x") + end; + end + def test_cache_opcodes_initialize str = 'test1-test2-test3-test4-test_5' re = '^([0-9a-zA-Z\-/]*){1,256}$'