From e2a2ee008bc8f17c60720ae42f629ad2097c8d7a Mon Sep 17 00:00:00 2001 From: Mads Ohm Larsen Date: Thu, 21 May 2020 13:04:01 +0200 Subject: [PATCH] Decoding JSON dates should respect newlines --- activesupport/lib/active_support/json/decoding.rb | 4 ++-- activesupport/test/json/decoding_test.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index b4bf882bc3..7ac49903b1 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -10,8 +10,8 @@ module ActiveSupport module JSON # matches YAML-formatted dates - DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/ - DATETIME_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})?)?)$/ + DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/ + DATETIME_REGEX = /\A(?:\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})?)?)\z/ class << self # Parses a JSON string (JavaScript Object Notation) into a hash. diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb index 7658b942aa..c6a6e76e45 100644 --- a/activesupport/test/json/decoding_test.rb +++ b/activesupport/test/json/decoding_test.rb @@ -40,6 +40,8 @@ class TestJSONDecoding < ActiveSupport::TestCase # 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" }, + %({"a": "Today is:\\n2020-05-21"}) => { "a" => "Today is:\n2020-05-21" }, + %({"a": "2007-01-01 01:12:34 Z\\nwas my birthday"}) => { "a" => "2007-01-01 01:12:34 Z\nwas my birthday" }, %([]) => [], %({}) => {}, %({"a":1}) => { "a" => 1 },