mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
parse dates to yaml in json arrays
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
7004434ad8
commit
a1edbf7206
2 changed files with 4 additions and 2 deletions
|
@ -29,7 +29,7 @@ module ActiveSupport
|
|||
def convert_json_to_yaml(json) #:nodoc:
|
||||
require 'strscan' unless defined? ::StringScanner
|
||||
scanner, quoting, marks, pos, times = ::StringScanner.new(json), false, [], nil, []
|
||||
while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
|
||||
while scanner.scan_until(/(\\['"]|['":,\\]|\\.|[\]])/)
|
||||
case char = scanner[1]
|
||||
when '"', "'"
|
||||
if !quoting
|
||||
|
@ -43,7 +43,7 @@ module ActiveSupport
|
|||
end
|
||||
quoting = false
|
||||
end
|
||||
when ":",","
|
||||
when ":",",", "]"
|
||||
marks << scanner.pos - 1 unless quoting
|
||||
when "\\"
|
||||
scanner.skip(/\\/)
|
||||
|
|
|
@ -17,6 +17,8 @@ class TestJSONDecoding < ActiveSupport::TestCase
|
|||
%({"matzue": "松江", "asakusa": "浅草"}) => {"matzue" => "松江", "asakusa" => "浅草"},
|
||||
%({"a": "2007-01-01"}) => {'a' => Date.new(2007, 1, 1)},
|
||||
%({"a": "2007-01-01 01:12:34 Z"}) => {'a' => Time.utc(2007, 1, 1, 1, 12, 34)},
|
||||
%(["2007-01-01 01:12:34 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34)],
|
||||
%(["2007-01-01 01:12:34 Z", "2007-01-01 01:12:35 Z"]) => [Time.utc(2007, 1, 1, 1, 12, 34), Time.utc(2007, 1, 1, 1, 12, 35)],
|
||||
# no time zone
|
||||
%({"a": "2007-01-01 01:12:34"}) => {'a' => "2007-01-01 01:12:34"},
|
||||
# invalid date
|
||||
|
|
Loading…
Reference in a new issue