From 5fd798d1ed52dde16f71ea7540c96a82b0d921da Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 2 Apr 2013 08:44:16 +0000 Subject: [PATCH] * re.c (rb_reg_to_s): suppress duplicated charclass warning. Regexp#to_s suppress extra its whole regexp options by calling onig_new with its source, but it doesn't call rb_reg_preprocess. Therefore its Unicode escapes (\u{XXXX}) are given as is, and it may cause duplicated charclass warning for example "[\u{33}]" (3 is duplicated) or "[\u{a}\u{b}]" (u is duplicated). [ruby-core:53649] [Bug #8151] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ re.c | 3 +++ test/ruby/test_regexp.rb | 3 +++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0fad107c80..4c15fda4a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Apr 2 17:38:20 2013 NARUSE, Yui + + * re.c (rb_reg_to_s): suppress duplicated charclass warning. + Regexp#to_s suppress extra its whole regexp options by calling + onig_new with its source, but it doesn't call rb_reg_preprocess. + Therefore its Unicode escapes (\u{XXXX}) are given as is, + and it may cause duplicated charclass warning for example + "[\u{33}]" (3 is duplicated) or "[\u{a}\u{b}]" (u is duplicated). + [ruby-core:53649] [Bug #8151] + Tue Apr 2 16:00:06 2013 NARUSE, Yui * vm_dump.c (rb_print_backtrace): separate to ease showing C backtrace. diff --git a/re.c b/re.c index 91d34eb0cd..16d7e3450c 100644 --- a/re.c +++ b/re.c @@ -571,12 +571,15 @@ rb_reg_to_s(VALUE re) } if (*ptr == ':' && ptr[len-1] == ')') { Regexp *rp; + VALUE verbose = ruby_verbose; + ruby_verbose = Qfalse; ++ptr; len -= 2; err = onig_new(&rp, ptr, ptr + len, ONIG_OPTION_DEFAULT, enc, OnigDefaultSyntax, NULL); onig_free(rp); + ruby_verbose = verbose; } if (err) { options = RREGEXP(re)->ptr->options; diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index e17cd6f962..3fa0fcf83c 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -915,6 +915,9 @@ class TestRegexp < Test::Unit::TestCase bug7471 = '[ruby-core:50344]' assert_warning('', bug7471) { Regexp.new('[\D]') =~ "\u3042" } + + bug8151 = '[ruby-core:53649]' + assert_warning(/\A\z/, bug8151) { Regexp.new('(?:[\u{33}])').to_s } end def test_property_warn