aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-22 21:09:56 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-22 21:09:56 +0000
commitec3056ae227fd79d706b2c6cdcdd8725df99c178 (patch)
tree59297ecb08dd48bf39b8530e4facafb19fd09b04
parentc05952c6a1687cac0526b0324b3659032aa7664a (diff)
downloadruby-ec3056ae227fd79d706b2c6cdcdd8725df99c178.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--ext/psych/lib/psych/scalar_scanner.rb6
-rw-r--r--test/psych/test_scalar_scanner.rb11
3 files changed, 25 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 421178595c..c719942f9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Oct 23 06:07:57 2012 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * 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@tenderlovemaking.com>
* ext/psych/lib/psych/scalar_scanner.rb: Fix scalar_scanner to
diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb
index 8727adecb4..ce4b767082 100644
--- a/ext/psych/lib/psych/scalar_scanner.rb
+++ b/ext/psych/lib/psych/scalar_scanner.rb
@@ -45,7 +45,11 @@ module Psych
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
diff --git a/test/psych/test_scalar_scanner.rb b/test/psych/test_scalar_scanner.rb
index 1397020c88..8483eabc7d 100644
--- a/test/psych/test_scalar_scanner.rb
+++ b/test/psych/test_scalar_scanner.rb
@@ -21,6 +21,17 @@ module Psych
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)