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

ruby-changes:33742

From: akr <ko1@a...>
Date: Mon, 5 May 2014 11:48:00 +0900 (JST)
Subject: [ruby-changes:33742] akr:r45823 (trunk): * lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime

akr	2014-05-05 11:47:53 +0900 (Mon, 05 May 2014)

  New Revision: 45823

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

  Log:
    * lib/time.rb (Time.strptime): Raise ArgumentError if Date._strptime
      doesn't extract date information.
      Reported by tadayoshi funaba.  [ruby-core:62349]

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45822)
+++ ChangeLog	(revision 45823)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May  5 11:44:03 2014  Tanaka Akira  <akr@f...>
+
+	* 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  <tadf@d...>
 
 	* ext/date/date_core.c (rt_rewrite_frags): a new feature (not a
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45822)
+++ lib/time.rb	(revision 45823)
@@ -416,6 +416,9 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L416
           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)
Index: NEWS
===================================================================
--- NEWS	(revision 45822)
+++ NEWS	(revision 45823)
@@ -77,6 +77,7 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L77
     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
 
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 45822)
+++ test/test_time.rb	(revision 45823)
@@ -423,6 +423,11 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L423
     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)

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

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