summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-14 15:45:42 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-14 15:45:42 +0000
commit108d1632e1ae83790692293047c3333220c1c9fd (patch)
treef18c7f46dd5d4f92a696cb1bb0b6724213e37df6
parent844f78f5564aeadb846cd7c8eec8e1dd507f7f60 (diff)
merge revision(s) 39967: [Backport #8193]
* time.c (num_exact): use to_r method only if to_int method is available. [ruby-core:53764] [Bug #8173] reported by Hiro Asari. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_time.rb1
-rw-r--r--time.c4
-rw-r--r--version.h2
4 files changed, 11 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 03b394bc63..d97686a1e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Apr 15 00:25:00 2013 Tanaka Akira <akr@fsij.org>
+
+ * time.c (num_exact): use to_r method only if to_int method is
+ available.
+ [ruby-core:53764] [Bug #8173] reported by Hiro Asari.
+
Mon Apr 15 00:22:09 2013 Shota Fukumori <her@sorah.jp>
* ext/objspace/objspace.c: Fix typo in doc. Patch by Sho Hashimoto.
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 15b6ae5bef..22df27067f 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -351,6 +351,7 @@ class TestTime < Test::Unit::TestCase
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
diff --git a/time.c b/time.c
index 7a877186e2..2173fcda8e 100644
--- a/time.c
+++ b/time.c
@@ -683,7 +683,9 @@ num_exact(VALUE v)
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;
}
diff --git a/version.h b/version.h
index 1b8c2ae5f7..588b3db9e0 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2013-04-15"
-#define RUBY_PATCHLEVEL 133
+#define RUBY_PATCHLEVEL 134
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 4