Skip to content
Browse files

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...
1 parent e605165 commit 73b9e43f5d3c9a9a0e5ff2048a5be52352e62eab @joshk joshk committed with Santiago Pastorino and Emilio Tagua Feb 12, 2011
Showing with 5 additions and 1 deletion.
  1. +1 −1 activesupport/lib/active_support/json/encoding.rb
  2. +4 −0 activesupport/test/json/decoding_test.rb
View
2 activesupport/lib/active_support/json/encoding.rb
@@ -23,7 +23,7 @@ class << self
module JSON
# matches YAML-formatted dates
- 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})?))$/
+ 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})?))$/
# Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
def self.encode(value, options = nil)
View
4 activesupport/test/json/decoding_test.rb
@@ -21,6 +21,10 @@ class TestJSONDecoding < ActiveSupport::TestCase
%({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
# invalid date
%({"a": "1089-10-40"}) => {'a' => "1089-10-40"},
+ # xmlschema date notation
+ %({"a": "2009-08-10T19:01:02Z"}) => {'a' => Time.utc(2009, 8, 10, 19, 1, 2)},
+ %({"a": "2009-08-10T19:01:02+02:00"}) => {'a' => Time.utc(2009, 8, 10, 17, 1, 2)},
+ %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.utc(2009, 8, 11, 00, 1, 2)},
# needs to be *exact*
%({"a": " 2007-01-01 01:12:34 Z "}) => {'a' => " 2007-01-01 01:12:34 Z "},
%({"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.