aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/json/decoding.rb13
-rw-r--r--activesupport/test/json/decoding_test.rb2
3 files changed, 13 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 895c1b4bab..780f8843a9 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix JSON decoder with nested quotes and commas. #9579 [zdennis]
+
* Hash#to_xml doesn't double-unescape. #8806 [Ezran]
* Added Array#rand #9170 [norbert]. Examples:
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index 60003a94e5..08446d3a83 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -15,19 +15,24 @@ module ActiveSupport
end
protected
+
# Ensure that ":" and "," are always followed by a space
def convert_json_to_yaml(json) #:nodoc:
scanner, quoting, marks = StringScanner.new(json), false, []
- while scanner.scan_until(/(['":,]|\\.)/)
+ while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
case char = scanner[1]
when '"', "'"
- quoting = quoting == char ? false : char
- when ":", ","
+ if !quoting
+ quoting = char
+ elsif quoting == char
+ quoting = false
+ end
+ when ":",","
marks << scanner.pos - 1 unless quoting
end
end
-
+
if marks.empty?
json
else
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index acdde21858..01796d5e99 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -8,6 +8,8 @@ class TestJSONDecoding < Test::Unit::TestCase
%({"returnTo":{"/categories":1}}) => {"returnTo" => {"/categories" => 1}},
%({"returnTo":[1,"a"]}) => {"returnTo" => [1, "a"]},
%({"returnTo":[1,"\\"a\\",", "b"]}) => {"returnTo" => [1, "\"a\",", "b"]},
+ %({a: "'", "b": "5,000"}) => {"a" => "'", "b" => "5,000"},
+ %({a: "a's, b's and c's", "b": "5,000"}) => {"a" => "a's, b's and c's", "b" => "5,000"},
%([]) => [],
%({}) => {},
%(1) => 1,