diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-08 07:21:05 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-08 07:21:05 +0000 |
commit | b12bb501496a3ad2822db14d13629629fad8fefb (patch) | |
tree | 5439660b5873af54e4dddb3d3c573143304c6137 /parse.y | |
parent | 9667f7953e1ca78e5acfa40e9573d1fcdbd3d1ea (diff) | |
download | ruby-b12bb501496a3ad2822db14d13629629fad8fefb.tar.gz |
* re.c (rb_reg_check_preprocess): new function for validating regexp
fragment.
* parse.y (regexp): invoke reg_fragment_check.
(reg_fragment_check): defined.
(reg_fragment_check_gen): defined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -444,6 +444,8 @@ static VALUE reg_compile_gen(struct parser_params*, VALUE, int); #define reg_compile(str,options) reg_compile_gen(parser, str, options) static void reg_fragment_setenc_gen(struct parser_params*, VALUE, int); #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, str, options) +static void reg_fragment_check_gen(struct parser_params*, VALUE, int); +#define reg_fragment_check(str,options) reg_fragment_check_gen(parser, str, options) #else #define remove_begin(node) (node) #endif /* !RIPPER */ @@ -3661,10 +3663,10 @@ regexp : tREGEXP_BEG xstring_contents tREGEXP_END nd_set_type(node, NODE_DREGX); } node->nd_cflag = options & RE_OPTION_MASK; - reg_fragment_setenc(node->nd_lit, options); + reg_fragment_check(node->nd_lit, options); for (list = node->nd_next; list; list = list->nd_next) { if (nd_type(list->nd_head) == NODE_STR) { - reg_fragment_setenc(list->nd_head->nd_lit, options); + reg_fragment_check(list->nd_head->nd_lit, options); } } break; @@ -8456,6 +8458,7 @@ dvar_curr_gen(struct parser_params *parser, ID id) } VALUE rb_reg_compile(VALUE str, int options); +VALUE rb_reg_check_preprocess(VALUE); static void reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) @@ -8475,6 +8478,19 @@ reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) } } +static void +reg_fragment_check_gen(struct parser_params* parser, VALUE str, int options) +{ + VALUE err; + reg_fragment_setenc_gen(parser, str, options); + err = rb_reg_check_preprocess(str); + if (err != Qnil) { + err = rb_obj_as_string(err); + compile_error(PARSER_ARG "%s", RSTRING_PTR(err)); + RB_GC_GUARD(err); + } +} + static VALUE reg_compile_gen(struct parser_params* parser, VALUE str, int options) { |