mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
codegen.c: fix regexp literal with encoding to pass nil for options; fix #6666
restore correct argument passing for Regexp.compile when encoding is
present but flags are not. regexp literals like /a/n should compile to
Regexp.compile("a", nil, "n") with 3 arguments, not
Regexp.compile("a", "n") with 2 arguments.
the bug was introduced during refactoring when the nil-insertion logic
for the options parameter was accidentally omitted. now properly inserts
OP_LOADNIL when flags are absent but encoding is present.
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5153,20 +5153,26 @@ codegen_regx(codegen_scope *s, node *varnode, int val)
|
||||
/* Generate regex pattern using common cons list function */
|
||||
gen_string(s, n->list, VAL);
|
||||
|
||||
/* Add flags if present */
|
||||
if (n->flags && *n->flags) {
|
||||
off = new_lit_cstr(s, n->flags);
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
/* Add flags and/or encoding if present */
|
||||
if ((n->flags && *n->flags) || (n->encoding && *n->encoding)) {
|
||||
/* Add flags (or nil if not present but encoding is) */
|
||||
if (n->flags && *n->flags) {
|
||||
off = new_lit_cstr(s, n->flags);
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
}
|
||||
else {
|
||||
genop_1(s, OP_LOADNIL, cursp());
|
||||
}
|
||||
push();
|
||||
argc++;
|
||||
}
|
||||
|
||||
/* Add encoding if present */
|
||||
if (n->encoding && *n->encoding) {
|
||||
off = new_lit_cstr(s, n->encoding);
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
push();
|
||||
argc++;
|
||||
/* Add encoding if present */
|
||||
if (n->encoding && *n->encoding) {
|
||||
off = new_lit_cstr(s, n->encoding);
|
||||
genop_2(s, OP_STRING, cursp(), off);
|
||||
push();
|
||||
argc++;
|
||||
}
|
||||
}
|
||||
|
||||
push(); /* space for a block */
|
||||
|
||||
Reference in New Issue
Block a user