From f944fd60f9f09580841c756ece795ce235d6bde2 Mon Sep 17 00:00:00 2001 From: Elad Meidar Date: Mon, 10 Aug 2009 17:15:42 -0400 Subject: [PATCH] [PATCH] fix JSON xmlschema date format parsing 2-3-stable --- activesupport/lib/active_support/json/encoding.rb | 2 +- activesupport/test/json/decoding_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index ffd2050..5991ef4 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -11,7 +11,7 @@ module ActiveSupport 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}[tT \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/ class << self delegate :encode, :to => :'ActiveSupport::JSON::Encoding' diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index d0d0ec7..b8f4f18 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -16,6 +16,10 @@ class TestJSONDecoding < ActiveSupport::TestCase %({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)}, # no time zone %({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"}, + # 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.parse("2009-08-10T19:01:02+02:00")}, + %({"a": "2009-08-10T19:01:02-05:00"}) => {'a' => Time.parse("2009-08-10T19:01:02-05:00")}, # 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"}, -- 1.6.0.2