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)