diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-02 02:29:36 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-12-02 03:57:41 +0900 |
commit | a607d62d8c5786087916413c369dbde0c62db573 (patch) | |
tree | ade98fe4de166625adf6fd871ef343f98eb8238f /compile.c | |
parent | ec83bd7356d639fe34f6843c4f1805c63cfdfa49 (diff) | |
download | ruby-a607d62d8c5786087916413c369dbde0c62db573.tar.gz |
[Bug #20033] Dynamic regexp should not assign captures
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -4213,11 +4213,28 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node) } static int -compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node) +compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) { int cnt; + + if (!RNODE_DREGX(node)->nd_next) { + VALUE match = RNODE_DREGX(node)->nd_lit; + if (RB_TYPE_P(match, T_REGEXP)) { + if (!popped) { + ADD_INSN1(ret, node, putobject, match); + RB_OBJ_WRITTEN(iseq, Qundef, match); + } + return COMPILE_OK; + } + } + CHECK(compile_dstr_fragments(iseq, ret, node, &cnt)); ADD_INSN2(ret, node, toregexp, INT2FIX(RNODE_DREGX(node)->nd_cflag), INT2FIX(cnt)); + + if (popped) { + ADD_INSN(ret, node, pop); + } + return COMPILE_OK; } @@ -9901,14 +9918,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no case NODE_EVSTR: CHECK(compile_evstr(iseq, ret, RNODE_EVSTR(node)->nd_body, popped)); break; - case NODE_DREGX:{ - compile_dregx(iseq, ret, node); - - if (popped) { - ADD_INSN(ret, node, pop); - } + case NODE_DREGX: + compile_dregx(iseq, ret, node, popped); break; - } case NODE_ONCE:{ int ic_index = body->ise_size++; const rb_iseq_t *block_iseq; |