1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use ! " " YAML string literal syntax rather than removing both quotes

This commit is contained in:
Aaron Patterson 2011-01-21 14:09:59 -08:00
parent 7642b7531d
commit 370bcd1a01
2 changed files with 5 additions and 7 deletions

View file

@ -20,8 +20,8 @@ module ActiveSupport
json = json.read json = json.read
end end
YAML.load(convert_json_to_yaml(json)) YAML.load(convert_json_to_yaml(json))
rescue *EXCEPTIONS rescue *EXCEPTIONS => e
raise ParseError, "Invalid JSON string" raise ParseError, "Invalid JSON string: '%s'" % json
end end
protected protected
@ -39,7 +39,7 @@ module ActiveSupport
if json[pos..scanner.pos-2] =~ DATE_REGEX if json[pos..scanner.pos-2] =~ DATE_REGEX
# found a date, track the exact positions of the quotes so we can # found a date, track the exact positions of the quotes so we can
# overwrite them with spaces later. # overwrite them with spaces later.
times << pos << scanner.pos times << pos
end end
quoting = false quoting = false
end end
@ -70,7 +70,7 @@ module ActiveSupport
chunk = scanner.peek(right_pos[i] - scanner.pos + 1) chunk = scanner.peek(right_pos[i] - scanner.pos + 1)
# overwrite the quotes found around the dates with spaces # overwrite the quotes found around the dates with spaces
while times.size > 0 && times[0] <= right_pos[i] while times.size > 0 && times[0] <= right_pos[i]
chunk[times.shift - scanner.pos - 1] = ' ' chunk.insert(times.shift - scanner.pos - 1, '! ')
end end
chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do
ustr = $1 ustr = $1

View file

@ -57,14 +57,12 @@ class TestJSONDecoding < ActiveSupport::TestCase
ActiveSupport.parse_json_times = true ActiveSupport.parse_json_times = true
silence_warnings do silence_warnings do
ActiveSupport::JSON.with_backend backend do ActiveSupport::JSON.with_backend backend do
assert_nothing_raised do
assert_equal expected, ActiveSupport::JSON.decode(json) assert_equal expected, ActiveSupport::JSON.decode(json)
end end
end end
end end
end end
end end
end
if backends.include?("JSONGem") if backends.include?("JSONGem")
test "json decodes time json with time parsing disabled" do test "json decodes time json with time parsing disabled" do