Skip to content

Commit

Permalink
use ! " " YAML string literal syntax rather than removing both quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 25, 2011
1 parent e4594f7 commit 5856fc5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions activesupport/lib/active_support/json/backends/yaml.rb
Expand Up @@ -13,8 +13,8 @@ def decode(json)
json = json.read
end
YAML.load(convert_json_to_yaml(json))
rescue ArgumentError
raise ParseError, "Invalid JSON string"
rescue *EXCEPTIONS => e
raise ParseError, "Invalid JSON string: '%s'" % json
end

protected
Expand All @@ -32,7 +32,7 @@ def convert_json_to_yaml(json) #:nodoc:
if valid_date?(json[pos..scanner.pos-2])
# 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
Expand Down Expand Up @@ -63,7 +63,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
Expand Down
4 changes: 1 addition & 3 deletions activesupport/test/json/decoding_test.rb
Expand Up @@ -63,9 +63,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
Expand Down

0 comments on commit 5856fc5

Please sign in to comment.