提交 370bcd1a 编写于 作者: A Aaron Patterson

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

上级 7642b753
......@@ -20,8 +20,8 @@ def decode(json)
json = json.read
end
YAML.load(convert_json_to_yaml(json))
rescue *EXCEPTIONS
raise ParseError, "Invalid JSON string"
rescue *EXCEPTIONS => e
raise ParseError, "Invalid JSON string: '%s'" % json
end
protected
......@@ -39,7 +39,7 @@ def convert_json_to_yaml(json) #:nodoc:
if json[pos..scanner.pos-2] =~ DATE_REGEX
# found a date, track the exact positions of the quotes so we can
# overwrite them with spaces later.
times << pos << scanner.pos
times << pos
end
quoting = false
end
......@@ -70,7 +70,7 @@ def convert_json_to_yaml(json) #:nodoc:
chunk = scanner.peek(right_pos[i] - scanner.pos + 1)
# overwrite the quotes found around the dates with spaces
while times.size > 0 && times[0] <= right_pos[i]
chunk[times.shift - scanner.pos - 1] = ' '
chunk.insert(times.shift - scanner.pos - 1, '! ')
end
chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do
ustr = $1
......
......@@ -57,9 +57,7 @@ class TestJSONDecoding < ActiveSupport::TestCase
ActiveSupport.parse_json_times = true
silence_warnings do
ActiveSupport::JSON.with_backend backend do
assert_nothing_raised do
assert_equal expected, ActiveSupport::JSON.decode(json)
end
assert_equal expected, ActiveSupport::JSON.decode(json)
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册