Permalink
Browse files

insns.def (opt_regexpmatch2): respect redefined match op

* insns.def (opt_regexpmatch2): respect redefined match op
  Thanks to Sam Rawlins for the fix.
* test/ruby/test_string.rb: test based on Tsuyoshi Sawada's report
  [Bug #9581]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent c1f1b93 commit 4101a5690e3e8cc4940052ab28c0466e200b256d normal committed Mar 11, 2014
Showing with 21 additions and 1 deletion.
  1. +7 −0 ChangeLog
  2. +1 −1 insns.def
  3. +13 −0 test/ruby/test_string.rb
View
@@ -1,3 +1,10 @@
+Wed Mar 12 07:26:05 2014 Eric Wong <e@80x24.org>
+
+ * insns.def (opt_regexpmatch2): respect redefined match op
+ Thanks to Sam Rawlins for the fix.
+ * test/ruby/test_string.rb: test based on Tsuyoshi Sawada's report
+ [Bug #9581]
+
Tue Mar 11 22:31:25 2014 Kazuki Tsujimoto <kazuki@callcc.net>
* ext/.document: add objspace/objspace_dump.c to document file.
View
@@ -2154,7 +2154,7 @@ opt_regexpmatch2
(VALUE obj2, VALUE obj1)
(VALUE val)
{
- if (RB_TYPE_P(obj2, T_STRING) &&
+ if (CLASS_OF(obj2) == rb_cString &&
BASIC_OP_UNREDEFINED_P(BOP_MATCH, STRING_REDEFINED_OP_FLAG)) {
val = rb_reg_match(obj1, obj2);
}
@@ -2219,6 +2219,19 @@ def =~(str)
assert_equal("foo", "" =~ //)
RUBY
end
+
+ class Bug9581 < String
+ def =~ re; :foo end
+ end
+
+ def test_regexp_match_subclass
+ s = Bug9581.new("abc")
+ r = /abc/
+ assert_equal(:foo, s =~ r)
+ assert_equal(:foo, s.send(:=~, r))
+ assert_equal(:foo, s.send(:=~, /abc/))
+ assert_equal(:foo, s =~ /abc/, "should not use optimized instruction")
+ end
end
class TestString2 < TestString

0 comments on commit 4101a56

Please sign in to comment.