diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2011-02-11 16:47:25 +0100 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-11 13:54:57 -0200 |
commit | b17d8d727fb510ad8b6eb4302984d290dc2e53b0 (patch) | |
tree | f482fbd339de6f1bbdbf38d9a07c119f6e18d119 /activesupport/lib/active_support/json/backends/yaml.rb | |
parent | f23bf7dbdbc0e0590083f0f288aa24f5b830e685 (diff) | |
download | rails-b17d8d727fb510ad8b6eb4302984d290dc2e53b0.tar.gz rails-b17d8d727fb510ad8b6eb4302984d290dc2e53b0.tar.bz2 rails-b17d8d727fb510ad8b6eb4302984d290dc2e53b0.zip |
Fixes an issue when decoding a json string which looks like a date but is invalid. This DateTime parse error is now caught and the original string is instead passed back [#6286 state:resolved]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activesupport/lib/active_support/json/backends/yaml.rb')
-rw-r--r-- | activesupport/lib/active_support/json/backends/yaml.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/backends/yaml.rb b/activesupport/lib/active_support/json/backends/yaml.rb index b1dd2a8107..077eda548a 100644 --- a/activesupport/lib/active_support/json/backends/yaml.rb +++ b/activesupport/lib/active_support/json/backends/yaml.rb @@ -36,7 +36,7 @@ module ActiveSupport quoting = char pos = scanner.pos elsif quoting == char - if json[pos..scanner.pos-2] =~ DATE_REGEX + if valid_date?(json[pos..scanner.pos-2]) # found a date, track the exact positions of the quotes so we can # overwrite them with spaces later. times << pos @@ -94,6 +94,16 @@ module ActiveSupport output end end + + private + def valid_date?(date_string) + begin + date_string =~ DATE_REGEX && DateTime.parse(date_string) + rescue ArgumentError + false + end + end + end end end |