Skip to content

Commit 4a6384e

Browse files
authored
Fix [Bug #20246]: Don't set next_head_exact if a capture is called (#9897)
1 parent 8a34586 commit 4a6384e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

regcomp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3395,7 +3395,7 @@ next_setup(Node* node, Node* next_node, regex_t* reg)
33953395
}
33963396
else if (type == NT_ENCLOSE) {
33973397
EncloseNode* en = NENCLOSE(node);
3398-
if (en->type == ENCLOSE_MEMORY) {
3398+
if (en->type == ENCLOSE_MEMORY && !IS_ENCLOSE_CALLED(en)) {
33993399
node = en->target;
34003400
goto retry;
34013401
}

test/ruby/test_regexp.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,6 +2045,11 @@ def test_bug_20212 # [Bug #20212]
20452045
100.times.each { assert(regex.match?(string)) }
20462046
end
20472047

2048+
def test_bug_20246 # [Bug #20246]
2049+
assert_equal '1.2.3', '1.2.3'[/(\d+)(\.\g<1>){2}/]
2050+
assert_equal '1.2.3', '1.2.3'[/((?:\d|foo|bar)+)(\.\g<1>){2}/]
2051+
end
2052+
20482053
def test_linear_time_p
20492054
assert_send [Regexp, :linear_time?, /a/]
20502055
assert_send [Regexp, :linear_time?, 'a']

0 commit comments

Comments
 (0)