diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | insns.def | 3 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 12 | ||||
-rw-r--r-- | vm.c | 2 |
4 files changed, 26 insertions, 2 deletions
@@ -1,3 +1,14 @@ +Thu Sep 26 16:51:00 2013 Shota Fukumori <her@sorah.jp> + + * insns.def (opt_regexpmatch2): Check String#=~ hasn't overridden + before calling rb_reg_match(). + + * test/ruby/test_string.rb: Test for above. + + * vm.c (vm_init_redefined_flag): Add BOP flag for String#=~ + + [ruby-core:57385] [Bug #8953] + Thu Sep 26 16:43:42 2013 Akinori MUSHA <knu@iDaemons.org> * misc/ruby-electric.el: Avoid use of the interactive function @@ -2098,7 +2098,8 @@ opt_regexpmatch2 (VALUE obj2, VALUE obj1) (VALUE val) { - if (RB_TYPE_P(obj2, T_STRING)) { + if (RB_TYPE_P(obj2, T_STRING) && + BASIC_OP_UNREDEFINED_P(BOP_MATCH, STRING_REDEFINED_OP_FLAG)) { val = rb_reg_match(obj1, obj2); } else { diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 4520464105..694d122372 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -2256,6 +2256,18 @@ class TestString < Test::Unit::TestCase assert_equal Encoding::UTF_8, a.encoding assert_equal Encoding::US_ASCII, b.encoding end + + def test_eq_tilde_can_be_overridden + assert_in_out_err([], <<-RUBY, ["foo"], []) + class String + def =~(str) + "foo" + end + end + + puts "" =~ // + RUBY + end end class TestString2 < TestString @@ -1095,7 +1095,7 @@ vm_init_redefined_flag(void) OP(Size, SIZE), (C(Array), C(String), C(Hash)); OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash)); OP(Succ, SUCC), (C(Fixnum), C(String), C(Time)); - OP(EqTilde, MATCH), (C(Regexp)); + OP(EqTilde, MATCH), (C(Regexp), C(String)); #undef C #undef OP } |