Skip to content
Browse files

Ignore bad timestamps. #82.

If something looks like a timestamp but has an invalid component,
treat it as a string instead of throwing an ArgumentError.
  • Loading branch information...
1 parent 06c8c7f commit 0c478a1ec7f8649ad416b181f8ef4c8a05860f17 @rsutphin committed Sep 11, 2012
Showing with 16 additions and 1 deletion.
  1. +5 −1 lib/psych/scalar_scanner.rb
  2. +11 −0 test/psych/test_scalar_scanner.rb
View
6 lib/psych/scalar_scanner.rb
@@ -45,7 +45,11 @@ def tokenize string
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
View
11 test/psych/test_scalar_scanner.rb
@@ -21,6 +21,17 @@ def test_scan_time
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)

0 comments on commit 0c478a1

Please sign in to comment.
Something went wrong with that request. Please try again.