[前][次][番号順一覧][スレッド一覧]

ruby-changes:26928

From: marcandre <ko1@a...>
Date: Wed, 30 Jan 2013 07:15:40 +0900 (JST)
Subject: [ruby-changes:26928] marcandRe: r38980 (trunk): * re.c (reg_operand): Simplify and reuse error handling [Bug #7539]

marcandre	2013-01-30 07:15:23 +0900 (Wed, 30 Jan 2013)

  New Revision: 38980

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38980

  Log:
    * re.c (reg_operand): Simplify and reuse error handling [Bug #7539]
    
    * test/ruby/test_regexp.rb: Test for above

  Modified files:
    trunk/ChangeLog
    trunk/re.c
    trunk/test/ruby/test_regexp.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38979)
+++ ChangeLog	(revision 38980)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jan 30 07:15:04 2013  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* re.c (reg_operand): Simplify and reuse error handling [Bug #7539]
+
+	* test/ruby/test_regexp.rb: Test for above
+
 Wed Jan 30 07:00:16 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* object.c: Improve error for failed implicit conversions [Bug #7539]
Index: re.c
===================================================================
--- re.c	(revision 38979)
+++ re.c	(revision 38980)
@@ -2667,12 +2667,7 @@ reg_operand(VALUE s, int check) https://github.com/ruby/ruby/blob/trunk/re.c#L2667
 	return rb_sym_to_s(s);
     }
     else {
-	VALUE tmp = rb_check_string_type(s);
-	if (check && NIL_P(tmp)) {
-	    rb_raise(rb_eTypeError, "can't convert %s to String",
-		     rb_obj_classname(s));
-	}
-	return tmp;
+	return (check ? rb_str_to_str : rb_check_string_type)(s);
     }
 }
 
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 38979)
+++ test/ruby/test_regexp.rb	(revision 38980)
@@ -929,4 +929,11 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L929
     # use Regexp.new instead of literal to ignore a parser warning.
     check(Regexp.new('[0-1-\\s]'), [' ', '-'], ['2', 'a'], bug6853)
   end
+
+  def test_error_message_on_failed_conversion
+    bug7539 = '[ruby-core:50733]'
+    assert_equal false, /x/=== 42
+    err = assert_raise(TypeError){ Regexp.quote(42) }
+    assert_equal 'no implicit conversion of Fixnum into String', err.message, bug7539
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]