diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-17 19:06:07 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-17 19:06:07 -0800 |
commit | 1caecdca27675e80f9a762875fcf7ced81b2d9f1 (patch) | |
tree | 69ec509719627f6392956a70c3eb72a3bd78ed47 /lib | |
parent | 40b1bc7cf72570f0645675b0e950de455566fe5e (diff) | |
download | psych-1caecdca27675e80f9a762875fcf7ced81b2d9f1.zip |
* ext/psych/lib/psych/scalar_scanner.rb: Strings that look like dates
should be treated as strings and not dates. Fixes #42
* test/psych/test_scalar_scanner.rb: corresponding tests.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/scalar_scanner.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index a265a2b..fa2d385 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -46,9 +46,13 @@ module Psych end when TIME parse_time string - when /^\d{4}-\d{1,2}-\d{1,2}$/ + when /^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/ require 'date' - Date.strptime(string, '%Y-%m-%d') + begin + Date.strptime(string, '%Y-%m-%d') + rescue ArgumentError + string + end when /^\.inf$/i 1 / 0.0 when /^-\.inf$/i |