Skip to content

Commit

Permalink
[Bug #20504] Remove regexp fragment checks in the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 28, 2024
1 parent 0ccc765 commit 931f376
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 33 deletions.
34 changes: 2 additions & 32 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,6 @@ static rb_ast_id_table_t *local_tbl(struct parser_params*);

static VALUE reg_compile(struct parser_params*, rb_parser_string_t*, int);
static void reg_fragment_setenc(struct parser_params*, rb_parser_string_t*, int);
int rb_parser_reg_fragment_check(struct parser_params*, rb_parser_string_t*, int, rb_parser_reg_fragment_error_func);
static void reg_fragment_error(struct parser_params *, VALUE);
#define reg_fragment_check(p, str, option) rb_parser_reg_fragment_check(p, str, option, reg_fragment_error)

static int literal_concat0(struct parser_params *p, rb_parser_string_t *head, rb_parser_string_t *tail);
static NODE *heredoc_dedent(struct parser_params*,NODE*);
Expand Down Expand Up @@ -13190,16 +13187,13 @@ new_regexp(struct parser_params *p, NODE *node, int options, const YYLTYPE *loc)
/* Check string is valid regex */
reg_compile(p, dreg->string, options);
}
else if (dreg->string) {
reg_fragment_check(p, dreg->string, options);
}
prev = node;
for (list = dreg->nd_next; list; list = RNODE_LIST(list->nd_next)) {
NODE *frag = list->nd_head;
enum node_type type = nd_type(frag);
if (type == NODE_STR || (type == NODE_DSTR && !RNODE_DSTR(frag)->nd_next)) {
rb_parser_string_t *tail = RNODE_STR(frag)->string;
if (reg_fragment_check(p, tail, options) && prev && RNODE_DREGX(prev)->string) {
if (prev && RNODE_DREGX(prev)->string) {
rb_parser_string_t *lit = prev == node ? dreg->string : RNODE_STR(RNODE_LIST(prev)->nd_head)->string;
if (!literal_concat0(p, lit, tail)) {
return NEW_NIL(loc); /* dummy node on error */
Expand Down Expand Up @@ -15381,30 +15375,6 @@ reg_fragment_setenc(struct parser_params* p, rb_parser_string_t *str, int option
if (c) reg_fragment_enc_error(p, str, c);
}

static void
reg_fragment_error(struct parser_params* p, VALUE err)
{
compile_error(p, "%"PRIsVALUE, err);
}

#ifndef RIPPER
int
rb_parser_reg_fragment_check(struct parser_params* p, rb_parser_string_t *str, int options, rb_parser_reg_fragment_error_func error)
{
VALUE err, str2;
reg_fragment_setenc(p, str, options);
/* TODO */
str2 = rb_str_new_parser_string(str);
err = rb_reg_check_preprocess(str2);
if (err != Qnil) {
err = rb_obj_as_string(err);
error(p, err);
return 0;
}
return 1;
}
#endif

#ifndef UNIVERSAL_PARSER
typedef struct {
struct parser_params* parser;
Expand Down Expand Up @@ -15503,7 +15473,7 @@ reg_compile(struct parser_params* p, rb_parser_string_t *str, int options)
if (NIL_P(re)) {
VALUE m = rb_attr_get(rb_errinfo(), idMesg);
rb_set_errinfo(err);
reg_fragment_error(p, m);
compile_error(p, "%"PRIsVALUE, m);
return Qnil;
}
return re;
Expand Down
1 change: 0 additions & 1 deletion test/.excludes-parsey/TestRubyLiteral.rb

This file was deleted.

0 comments on commit 931f376

Please sign in to comment.