Skip to content
This repository
Browse code

Updated the json date regex to recognize xmlschema formatted date tim…

…es during json decoding. [#3031 state:resolved]

Signed-off-by: Santiago Pastorino and Emilio Tagua <santiago+emilioe@wyeworks.com>
  • Loading branch information...
commit 73b9e43f5d3c9a9a0e5ff2048a5be52352e62eab 1 parent e605165
Josh Kalderimis joshk authored Santiago Pastorino and Emilio Tagua committed
2  activesupport/lib/active_support/json/encoding.rb
@@ -23,7 +23,7 @@ class << self
23 23
24 24 module JSON
25 25 # matches YAML-formatted dates
26   - DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
  26 + DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
27 27
28 28 # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
29 29 def self.encode(value, options = nil)
4 activesupport/test/json/decoding_test.rb
@@ -21,6 +21,10 @@ class TestJSONDecoding < ActiveSupport::TestCase
21 21 %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
22 22 # invalid date
23 23 %({"a": "1089-10-40"}) => {'a' => "1089-10-40"},
  24 + # xmlschema date notation
  25 + %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)},
  26 + %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)},
  27 + %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)},
24 28 # needs to be *exact*
25 29 %({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
26 30 %({"a": "2007-01-01 : it's your birthday"}) => {'a' => "2007-01-01 : it's your birthday"},

0 comments on commit 73b9e43

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