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

ruby-changes:27915

From: akr <ko1@a...>
Date: Wed, 27 Mar 2013 20:39:36 +0900 (JST)
Subject: [ruby-changes:27915] akr:r39967 (trunk): * time.c (num_exact): use to_r method only if to_int method is

akr	2013-03-27 20:37:59 +0900 (Wed, 27 Mar 2013)

  New Revision: 39967

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

  Log:
    * time.c (num_exact): use to_r method only if to_int method is
      available.
      [ruby-core:53764] [Bug #8173] reported by Hiro Asari.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_time.rb
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 39966)
+++ time.c	(revision 39967)
@@ -683,7 +683,9 @@ num_exact(VALUE v) https://github.com/ruby/ruby/blob/trunk/time.c#L683
 
       default:
         if ((tmp = rb_check_funcall(v, rb_intern("to_r"), 0, NULL)) != Qundef) {
-            if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror;
+            /* test to_int method availability to reject non-Numeric
+             * objects such as String, Time, etc which have to_r method. */
+            if (!rb_respond_to(v, rb_intern("to_int"))) goto typeerror;
             v = tmp;
             break;
         }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39966)
+++ ChangeLog	(revision 39967)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar 27 12:45:41 2013  Tanaka Akira  <akr@f...>
+
+	* time.c (num_exact): use to_r method only if to_int method is
+	  available.
+	  [ruby-core:53764] [Bug #8173] reported by Hiro Asari.
+
 Wed Mar 27 12:07:40 2013  Tanaka Akira  <akr@f...>
 
 	* test/-ext-/num2int/test_num2int.rb (test_num2ll): test LLONG_MIN,
Index: test/ruby/test_time.rb
===================================================================
--- test/ruby/test_time.rb	(revision 39966)
+++ test/ruby/test_time.rb	(revision 39967)
@@ -351,6 +351,7 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L351
     end
     assert_raise(ArgumentError) { Time.gm(2000, 1, 1, 0, 0, -(2**31), :foo, :foo) }
     o = Object.new
+    def o.to_int; 0; end
     def o.to_r; nil; end
     assert_raise(TypeError) { Time.gm(2000, 1, 1, 0, 0, o, :foo, :foo) }
     def o.to_r; ""; end

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

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