diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-17 21:37:48 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-17 21:37:48 +0000 |
commit | 71e33d96509d0a8fe698b228579e5a7adef48601 (patch) | |
tree | 5266418ba28118a085a615773cd78f1f7bef1452 /activesupport/lib/active_support/json | |
parent | 6b68b215c2eee237248dcebbbe2c9258ebd8ca57 (diff) | |
download | rails-71e33d96509d0a8fe698b228579e5a7adef48601.tar.gz rails-71e33d96509d0a8fe698b228579e5a7adef48601.tar.bz2 rails-71e33d96509d0a8fe698b228579e5a7adef48601.zip |
Fix JSON decoder with nested quotes and commas. Closes #9579.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7506 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 13 |
1 files changed, 9 insertions, 4 deletions
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 |