diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-03 12:31:25 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-08-03 12:31:25 +0000 |
commit | 18cf70ebf636b9754760b12961bebb125af6ec39 (patch) | |
tree | d35f49337331491b60b3f1a02c2b7eba2e37e1c8 | |
parent | 340805cfad9ca5072ab79cdbc1cf00b98c764caf (diff) | |
download | ruby-18cf70ebf636b9754760b12961bebb125af6ec39.tar.gz |
parse.y: reg_fragment_enc_error
* parse.y (reg_fragment_enc_error): compile_error is different
between parser and ripper. [ruby-core:76397] [Bug #12651]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | parse.y | 52 | ||||
-rw-r--r-- | test/ripper/test_ripper.rb | 26 |
3 files changed, 71 insertions, 12 deletions
@@ -1,3 +1,8 @@ +Wed Aug 3 21:31:23 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * parse.y (reg_fragment_enc_error): compile_error is different + between parser and ripper. [ruby-core:76397] [Bug #12651] + Wed Aug 3 17:15:06 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * object.c (rb_obj_clone2): restrict freeze option to true other @@ -549,11 +549,15 @@ static VALUE new_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE op static VALUE new_attr_op_assign_gen(struct parser_params *parser, VALUE lhs, VALUE type, VALUE attr, VALUE op, VALUE rhs); #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs)) +static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *); + #endif /* !RIPPER */ #define new_op_assign(lhs, op, rhs) new_op_assign_gen(parser, (lhs), (op), (rhs)) -RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg); +RUBY_FUNC_EXPORTED VALUE rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options); +RUBY_FUNC_EXPORTED int rb_reg_fragment_setenc(struct parser_params*, VALUE, int); + static ID formal_argument_gen(struct parser_params*, ID); #define formal_argument(id) formal_argument_gen(parser, (id)) @@ -4052,7 +4056,7 @@ regexp : tREGEXP_BEG regexp_contents tREGEXP_END $3 = RNODE(opt)->nd_rval; options = (int)RNODE(opt)->nd_tag; } - if (src && NIL_P(rb_parser_reg_compile(parser, src, options, &err))) { + if (src && NIL_P(parser_reg_compile(parser, src, options, &err))) { compile_error(PARSER_ARG "%"PRIsVALUE, err); } $$ = dispatch2(regexp_literal, $2, $3); @@ -10536,9 +10540,17 @@ dvar_curr_gen(struct parser_params *parser, ID id) vtable_included(lvtbl->vars, id)); } -#ifndef RIPPER static void -reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) +reg_fragment_enc_error(struct parser_params* parser, VALUE str, int c) +{ + compile_error(PARSER_ARG + "regexp encoding option '%c' differs from source encoding '%s'", + c, rb_enc_name(rb_enc_get(str))); +} + +#ifndef RIPPER +int +rb_reg_fragment_setenc(struct parser_params* parser, VALUE str, int options) { int c = RE_OPTION_ENCODING_IDX(options); @@ -10568,12 +10580,17 @@ reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) rb_enc_associate(str, rb_ascii8bit_encoding()); } } - return; + return 0; error: - compile_error(PARSER_ARG - "regexp encoding option '%c' differs from source encoding '%s'", - c, rb_enc_name(rb_enc_get(str))); + return c; +} + +static void +reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options) +{ + int c = rb_reg_fragment_setenc(parser, str, options); + if (c) reg_fragment_enc_error(parser, str, c); } static int @@ -10640,6 +10657,12 @@ static VALUE parser_reg_compile(struct parser_params* parser, VALUE str, int options) { reg_fragment_setenc(str, options); + return rb_parser_reg_compile(parser, str, options); +} + +VALUE +rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options) +{ return rb_reg_compile(str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline); } @@ -10664,19 +10687,24 @@ reg_compile_gen(struct parser_params* parser, VALUE str, int options) } return re; } - -VALUE -rb_parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg) +#else +static VALUE +parser_reg_compile(struct parser_params* parser, VALUE str, int options, VALUE *errmsg) { VALUE err = rb_errinfo(); - VALUE re = parser_reg_compile(parser, str, options); + VALUE re; + int c = rb_reg_fragment_setenc(parser, str, options); + if (c) reg_fragment_enc_error(parser, str, c); + re = rb_parser_reg_compile(parser, str, options); if (NIL_P(re)) { *errmsg = rb_attr_get(rb_errinfo(), idMesg); rb_set_errinfo(err); } return re; } +#endif +#ifndef RIPPER NODE* rb_parser_append_print(VALUE vparser, NODE *node) { diff --git a/test/ripper/test_ripper.rb b/test/ripper/test_ripper.rb index 7631b91042..afe7183ff4 100644 --- a/test/ripper/test_ripper.rb +++ b/test/ripper/test_ripper.rb @@ -72,4 +72,30 @@ class TestRipper::Ripper < Test::Unit::TestCase ripper.parse assert_not_predicate(ripper, :error?, bug11932) end + + def test_regexp_enc_error + assert_separately(%w[-rripper], "#{<<-"begin;"}\n#{<<-"end;"}") + begin; + bug12651 = '[ruby-core:76397] [Bug #12651]' + src = <<-END +<%- @title = '\u{5bff 9650 7121}' -%> +<%- content_for :foo, render(partial: 'bar', locals: {baz: 2}) -%> + +<div class="dead beef"> + <h2 class="dead beef">\u{5bff 9650 7121}</h2> +</div> +<div class="dead beef">\u{5bff 9650 7121 3002}<br class="dead beef">\u{5bff 9650 7121 3002}</div> + +<div class="dead beef"> + <div class="dead beef"> + <label class="dead beef">\u{5bff 9650 7121}</label> + <div class="dead beef"> + <div class="dead beef"><%= @baz %></div> + </div> + </div> +</div> + END + assert_nil(Ripper.sexp(src), bug12651) + end; + end end if ripper_test |