diff --git a/src/regexp.c b/src/regexp.c index e4bf74c142..6aa470bf7c 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -158,6 +158,11 @@ pm_regexp_parse_range_quantifier(pm_regexp_parser_t *parser) { } state = PM_REGEXP_RANGE_QUANTIFIER_STATE_START; while (1) { + if (parser->cursor >= parser->end) { + parser->cursor = savepoint; + return true; + } + switch (state) { case PM_REGEXP_RANGE_QUANTIFIER_STATE_START: switch (*parser->cursor) { diff --git a/test/prism/regexp_test.rb b/test/prism/regexp_test.rb index 297020fc72..cde0c23f97 100644 --- a/test/prism/regexp_test.rb +++ b/test/prism/regexp_test.rb @@ -186,6 +186,10 @@ def test_fake_range_quantifier_because_of_spaces assert_valid_regexp("foo{1, 2}") end + def test_fake_range_quantifier_because_unclosed + assert_valid_regexp("\\A{") + end + ############################################################################ # These test that flag values are correct. ############################################################################