ruby-changes:25236
From: tenderlove <ko1@a...>
Date: Tue, 23 Oct 2012 06:10:09 +0900 (JST)
Subject: [ruby-changes:25236] tenderlove:r37288 (trunk): * ext/psych/lib/psych/scalar_scanner.rb: Ignore bad timestamps. If
tenderlove 2012-10-23 06:09:56 +0900 (Tue, 23 Oct 2012) New Revision: 37288 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37288 Log: * ext/psych/lib/psych/scalar_scanner.rb: Ignore bad timestamps. If something looks like a timestamp but has an invalid component, treat it as a string instead of throwing an ArgumentError. Thanks Rhett Sutphin! * test/psych/test_scalar_scanner.rb: appropriate tests. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/scalar_scanner.rb trunk/test/psych/test_scalar_scanner.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37287) +++ ChangeLog (revision 37288) @@ -1,3 +1,12 @@ +Tue Oct 23 06:07:57 2012 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/scalar_scanner.rb: Ignore bad timestamps. If + something looks like a timestamp but has an invalid component, treat + it as a string instead of throwing an ArgumentError. + Thanks Rhett Sutphin! + + * test/psych/test_scalar_scanner.rb: appropriate tests. + Tue Oct 23 06:04:07 2012 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/scalar_scanner.rb: Fix scalar_scanner to Index: ext/psych/lib/psych/scalar_scanner.rb =================================================================== --- ext/psych/lib/psych/scalar_scanner.rb (revision 37287) +++ ext/psych/lib/psych/scalar_scanner.rb (revision 37288) @@ -45,7 +45,11 @@ string end when TIME - parse_time string + begin + parse_time string + rescue ArgumentError + string + end when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/ require 'date' begin Index: test/psych/test_scalar_scanner.rb =================================================================== --- test/psych/test_scalar_scanner.rb (revision 37287) +++ test/psych/test_scalar_scanner.rb (revision 37288) @@ -21,6 +21,17 @@ end end + def test_scan_bad_time + [ '2001-12-15T02:59:73.1Z', + '2001-12-14t90:59:43.10-05:00', + '2001-92-14 21:59:43.10 -5', + '2001-12-15 92:59:43.10', + '2011-02-24 81:17:06 -0800', + ].each do |time_str| + assert_equal time_str, @ss.tokenize(time_str) + end + end + def test_scan_bad_dates x = '2000-15-01' assert_equal x, @ss.tokenize(x) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/