summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-26 07:58:28 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-26 07:58:28 +0000
commitc4b4e77c72b42f0a69c6a825954ec768d1b2375b (patch)
tree82428b01d29a336f150a95c1655410260bf5c078
parent26f7f7da272cfa4ad4a81758d4caef6528b6efbd (diff)
* 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
-rw-r--r--ChangeLog11
-rw-r--r--insns.def3
-rw-r--r--test/ruby/test_string.rb12
-rw-r--r--vm.c2
4 files changed, 26 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index f493fe3..7b0d3a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/insns.def b/insns.def
index a73501f..740ff5d 100644
--- a/insns.def
+++ b/insns.def
@@ -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 4520464..694d122 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
diff --git a/vm.c b/vm.c
index d647ab4..a43f3d6 100644
--- a/vm.c
+++ b/vm.c
@@ -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
}