From c2a87a1fa138936dc8dca1b66fb719eec7f00b3a Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 5 May 2014 02:47:53 +0000 Subject: * lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime doesn't extract date information. Reported by tadayoshi funaba. [ruby-core:62349] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ NEWS | 1 + lib/time.rb | 3 +++ test/test_time.rb | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9ceaca2094..73b959ba4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon May 5 11:44:03 2014 Tanaka Akira + + * lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime + doesn't extract date information. + Reported by tadayoshi funaba. [ruby-core:62349] + Mon May 5 01:12:27 2014 Tadayoshi Funaba * ext/date/date_core.c (rt_rewrite_frags): a new feature (not a diff --git a/NEWS b/NEWS index 97b56e9174..379d5870a5 100644 --- a/NEWS +++ b/NEWS @@ -77,6 +77,7 @@ with all sufficient information, see the ChangeLog file. fixed-offset Time objects. It is happen when usual localtime doesn't preserve the offset from UTC. * Time.httpdate produces always UTC Time object. + * Time.strptime raises ArgumentError when no date information. === Built-in global variables compatibility issues diff --git a/lib/time.rb b/lib/time.rb index b8e3b22998..a10c20bedc 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -416,6 +416,9 @@ class Time force_zone!(t, zone) end else + if !d[:year] && !d[:mon] && !d[:mday] && !d[:hour] && !d[:min] && !d[:sec] && !d[:sec_fraction] + raise ArgumentError, "no time information in #{date.inspect}" + end year = d[:year] year = yield(year) if year && block_given? t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now) diff --git a/test/test_time.rb b/test/test_time.rb index 54c2166ec5..b3dd40060c 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -423,6 +423,11 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc: assert_equal(false, Time.strptime('0', '%s').utc?) end + def test_strptime_empty + assert_raise(ArgumentError) { Time.strptime('', '') } + assert_raise(ArgumentError) { Time.strptime('+09:00', '%z') } + end + def test_strptime_s_z t = Time.strptime('0 +0100', '%s %z') assert_equal(0, t.to_r) -- cgit v1.2.3