diff --git a/regcomp.c b/regcomp.c index 13762364aa..38bfed5631 100644 --- a/regcomp.c +++ b/regcomp.c @@ -3395,7 +3395,7 @@ next_setup(Node* node, Node* next_node, regex_t* reg) } else if (type == NT_ENCLOSE) { EncloseNode* en = NENCLOSE(node); - if (en->type == ENCLOSE_MEMORY) { + if (en->type == ENCLOSE_MEMORY && !IS_ENCLOSE_CALLED(en)) { node = en->target; goto retry; } diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index e6eee24b2e..9eab99d677 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -2045,6 +2045,11 @@ class TestRegexp < Test::Unit::TestCase 100.times.each { assert(regex.match?(string)) } end + def test_bug_20246 # [Bug #20246] + assert_equal '1.2.3', '1.2.3'[/(\d+)(\.\g<1>){2}/] + assert_equal '1.2.3', '1.2.3'[/((?:\d|foo|bar)+)(\.\g<1>){2}/] + end + def test_linear_time_p assert_send [Regexp, :linear_time?, /a/] assert_send [Regexp, :linear_time?, 'a']