ruby-changes:34789
From: nobu <ko1@a...>
Date: Sat, 19 Jul 2014 11:56:49 +0900 (JST)
Subject: [ruby-changes:34789] nobu:r46872 (trunk): Fix `Time.parse` for out of range arguments with an offset
nobu 2014-07-19 11:56:39 +0900 (Sat, 19 Jul 2014) New Revision: 46872 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46872 Log: Fix `Time.parse` for out of range arguments with an offset * lib/time.rb (Time#apply_offset): Guards against a `nil` return value from `Time.month_days` when offsetting date. Out of range values are then caught when `Time.utc` is called (as usual). Previously a `nil` return value from `Time.month_days` would have the `<` operator called on it, and raise `NoMethodError`. [fix GH-667] * lib/rdoc/parser/changelog.rb (RDoc#parse_entries): fix dirty hack. Modified files: trunk/ChangeLog trunk/lib/rdoc/parser/changelog.rb trunk/lib/time.rb trunk/test/test_time.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46871) +++ ChangeLog (revision 46872) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jul 19 11:56:36 2014 Grey Baker <greysteil@g...> + + * lib/time.rb (Time#apply_offset): Guards against a `nil` return + value from `Time.month_days` when offsetting date. Out of range + values are then caught when `Time.utc` is called (as usual). + + Previously a `nil` return value from `Time.month_days` would + have the `<` operator called on it, and raise `NoMethodError`. + [fix GH-667] + + * lib/rdoc/parser/changelog.rb (RDoc#parse_entries): fix dirty hack. + Sat Jul 19 06:19:01 2014 Masaki Suketa <masaki.suketa@n...> * ext/win32ole/win32ole.c: refactoring. Index: lib/rdoc/parser/changelog.rb =================================================================== --- lib/rdoc/parser/changelog.rb (revision 46871) +++ lib/rdoc/parser/changelog.rb (revision 46872) @@ -145,10 +145,14 @@ class RDoc::Parser::ChangeLog < RDoc::Pa https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L145 # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other" entry_name = nil unless entry_name =~ /#{time.year}/ rescue NoMethodError + # HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent time, = entry_name.split ' ', 2 - time = Time.parse time rescue ArgumentError - entry_name = nil + if /out of range/ =~ $!.message + time = Time.parse(entry_name.split(' ', 2)[0]) rescue entry_name = nil + else + entry_name = nil + end end entry_body = [] Index: lib/time.rb =================================================================== --- lib/time.rb (revision 46871) +++ lib/time.rb (revision 46872) @@ -214,7 +214,8 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L214 if o != 0 then hour += o; o, hour = hour.divmod(24); off += o end if off != 0 day += off - if month_days(year, mon) < day + days = month_days(year, mon) + if days and days < day mon += 1 if 12 < mon mon = 1 Index: test/test_time.rb =================================================================== --- test/test_time.rb (revision 46871) +++ test/test_time.rb (revision 46872) @@ -307,6 +307,9 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L307 assert_raise(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=C5=DA),?= 10 2 2001 23:32:26 +0900 (JST)") } assert_raise(ArgumentError) { Time.rfc2822("\307\341\314\343\332\311, 30 \344\346\335\343\310\321 2001 10:01:06") } assert_raise(ArgumentError) { Time.rfc2822("=?iso-8859-1?Q?(=BF=E5),?= 12 =?iso-8859-1?Q?9=B7=EE?= 2001 14:52:41\n+0900 (JST)") } + + # Out of range arguments + assert_raise(ArgumentError) { Time.parse("2014-13-13T18:00:00-0900") } end def test_zone_0000 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/