ruby-changes:45148
From: usa <ko1@a...>
Date: Tue, 27 Dec 2016 20:14:37 +0900 (JST)
Subject: [ruby-changes:45148] usa:r57221 (ruby_2_2): merge revision(s) 57123: [Backport #13054]
usa 2016-12-27 20:14:32 +0900 (Tue, 27 Dec 2016) New Revision: 57221 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57221 Log: merge revision(s) 57123: [Backport #13054] re.c: consider the case of RMatch::regexp is nil Follow r49675, r57098 and r57110. Don't assume RMatch::regexp always contains a valid Regexp instance; it will be Qnil if the MatchData is created by rb_backref_set_string(). [ruby-core:78741] [Bug #13054] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/re.c branches/ruby_2_2/test/ruby/test_regexp.rb branches/ruby_2_2/version.h Index: ruby_2_2/test/ruby/test_regexp.rb =================================================================== --- ruby_2_2/test/ruby/test_regexp.rb (revision 57220) +++ ruby_2_2/test/ruby/test_regexp.rb (revision 57221) @@ -559,16 +559,33 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_regexp.rb#L559 end def test_match_without_regexp + # create a MatchData for each assertion because the internal state may change + test = proc {|&blk| "abc".sub("a", ""); blk.call($~) } + bug10877 = '[ruby-core:68209] [Bug #10877]' - "abc".sub("a", "") - assert_raise_with_message(IndexError, /foo/, bug10877) {$~["foo"]} + test.call {|m| assert_raise_with_message(IndexError, /foo/, bug10877) {m["foo"]} } key = "\u{3042}" [Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc| idx = key.encode(enc) - EnvUtil.with_default_external(enc) do - assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]} - end + test.call {|m| + EnvUtil.with_default_external(enc) do + assert_raise_with_message(IndexError, /#{idx}/, bug10877) {m[idx]} + end + } end + test.call {|m| assert_equal(/a/, m.regexp) } + test.call {|m| assert_equal("abc", m.string) } + test.call {|m| assert_equal(1, m.size) } + test.call {|m| assert_equal(0, m.begin(0)) } + test.call {|m| assert_equal(1, m.end(0)) } + test.call {|m| assert_equal([0, 1], m.offset(0)) } + test.call {|m| assert_equal([], m.captures) } + test.call {|m| assert_equal([], m.names) } + test.call {|m| assert_equal(/a/.match("abc"), m) } + test.call {|m| assert_equal(/a/.match("abc").hash, m.hash) } + test.call {|m| assert_equal("bc", m.post_match) } + test.call {|m| assert_equal("", m.pre_match) } + test.call {|m| assert_equal(["a", nil], m.values_at(0, 1)) } end def test_last_match Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 57220) +++ ruby_2_2/version.h (revision 57221) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.7" #define RUBY_RELEASE_DATE "2016-12-27" -#define RUBY_PATCHLEVEL 411 +#define RUBY_PATCHLEVEL 412 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 12 Index: ruby_2_2/re.c =================================================================== --- ruby_2_2/re.c (revision 57220) +++ ruby_2_2/re.c (revision 57221) @@ -1088,6 +1088,8 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/re.c#L1088 match_names(VALUE match) { match_check(match); + if (NIL_P(RMATCH(match)->regexp)) + return rb_ary_new_capa(0); return rb_reg_names(RMATCH(match)->regexp); } @@ -2743,7 +2745,7 @@ match_hash(VALUE match) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/re.c#L2745 const struct re_registers *regs; st_index_t hashval = rb_hash_start(rb_str_hash(RMATCH(match)->str)); - rb_hash_uint(hashval, reg_hash(RMATCH(match)->regexp)); + rb_hash_uint(hashval, reg_hash(match_regexp(match))); regs = RMATCH_REGS(match); hashval = rb_hash_uint(hashval, regs->num_regs); hashval = rb_hash_uint(hashval, rb_memhash(regs->beg, regs->num_regs * sizeof(*regs->beg))); @@ -2768,7 +2770,7 @@ match_equal(VALUE match1, VALUE match2) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/re.c#L2770 if (match1 == match2) return Qtrue; if (!RB_TYPE_P(match2, T_MATCH)) return Qfalse; if (!rb_str_equal(RMATCH(match1)->str, RMATCH(match2)->str)) return Qfalse; - if (!rb_reg_equal(RMATCH(match1)->regexp, RMATCH(match2)->regexp)) return Qfalse; + if (!rb_reg_equal(match_regexp(match1), match_regexp(match2))) return Qfalse; regs1 = RMATCH_REGS(match1); regs2 = RMATCH_REGS(match2); if (regs1->num_regs != regs2->num_regs) return Qfalse; Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 57220) +++ ruby_2_2/ChangeLog (revision 57221) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Dec 27 20:13:12 2016 Kazuki Yamaguchi <k@r...> + + * re.c (match_{names,hash,equal}): consider the case of RMatch::regexp + is nil. + + Don't assume RMatch::regexp always contains a valid Regexp instance; + it will be Qnil if the MatchData is created by + rb_backref_set_string(). [Bug #13054] + Tue Dec 27 20:02:43 2016 Kazuki Yamaguchi <k@r...> * array.c (rb_ary_{repeated_,}combination): check array length every Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r57123 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/