Commit 0b3b357e
0b3b357ec2c0Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(regexp): bare quantifier raises instead of looping (#825)
Regexp.new("*") (or /+/, /?/) caused the compiler to spin
forever: compile_atom returned without consuming the quantifier
character, compile_quantified saw no atom and returned, and the
surrounding compile_seq loop re-entered with the same state.
When compile_atom emits nothing but the next char is a bare quantifier, raise compile_error ("target of repeat operator is not specified") instead -- matches CRuby's RegexpError for the same input.
Closes #825
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 0b3b357ec2c0
- Parent
- e9be1f479dcb
lib/regexp/re_compile.cmodifiedView file
@@ -680,7 +680,18 @@
680680
{681681
uint32_t start = c->code_len;682682
compile_atom(c);683-
if (c->code_len == start) return; /* no atom emitted */683+
if (c->code_len == start) {684+
/* Issue #825: when compile_atom emitted nothing AND the next685+
char is a bare quantifier (star, plus, question), the686+
surrounding seq loop has nothing to advance with and spins687+
forever. Raise instead. CRuby: RegexpError "target of688+
repeat operator is not specified". */689+
int qch = peek(c);690+
if (qch == '*' || qch == '+' || qch == '?') {691+
compile_error(c, "target of repeat operator is not specified");692+
}693+
return; /* no atom emitted, no quantifier -- caller handles */694+
}684695
685696
int ch = peek(c);686697
if (ch == '*' || ch == '+' || ch == '?') {