Bug #2945: Regexp#=== is failed by an exception when the exception is occurred in method_missing
http://redmine.ruby-lang.org/issues/show/2945

Author: Kenta Murata
Status: Open, Priority: Normal
Category: core, Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2010-03-08 trunk 26849) [x86_64-darwin10.2.0]

When an exception is occurred in method_missing,
Regexp#=== is failed by the exception.
Is this valid behavior?

  o = Object.new
  class <<
    def method_missing(m, *args)
      raise "XXX" if m == :to_str
    end
  end
  /aaa/ === o # =:> `method_missing': XXX (RuntimeError)


If correct this, apply the following patch.

diff --git a/re.c b/re.c
index 6ec3646..8a38155 100644
--- a/re.c
+++ b/re.c
@@ -2685,6 +2685,12 @@ rb_reg_match(VALUE re, VALUE str)
     return LONG2FIX(pos);
 }
 
+static VALUE
+reg_check_operand(VALUE str)
+{
+    return reg_operand(str, FALSE);
+}
+
 /*
  *  call-seq:
  *     rxp === str   => true or false
@@ -2708,7 +2714,7 @@ rb_reg_eqq(VALUE re, VALUE str)
 {
     long start;
 
-    str = reg_operand(str, FALSE);
+    str = rb_protect(reg_check_operand, str, 0);
     if (NIL_P(str)) {
 	rb_backref_set(Qnil);
 	return Qfalse;


----------------------------------------
http://redmine.ruby-lang.org