1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
sorah 2013-09-26 07:58:28 +00:00
parent 26f7f7da27
commit c4b4e77c72
4 changed files with 26 additions and 2 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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

2
vm.c
View file

@ -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
}