diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-10-26 03:22:02 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-10-26 03:22:02 +0000 |
commit | 34c125d774ed817d45bb11a5173f989ca16cc514 (patch) | |
tree | 804c6c0bb20e94323cd36c04869051616a6c7a58 /activesupport/lib | |
parent | 8b2a6014a2971159c2169704ee5d3402f8d8d1a3 (diff) | |
download | rails-34c125d774ed817d45bb11a5173f989ca16cc514.tar.gz rails-34c125d774ed817d45bb11a5173f989ca16cc514.tar.bz2 rails-34c125d774ed817d45bb11a5173f989ca16cc514.zip |
Fix JSON encoding/decoding bugs dealing with /'s. Closes #9990 [Rick, theamazingrando]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8026 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/json/encoders/string.rb | 19 |
2 files changed, 12 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb index 7d07a60e33..f24aa9e57c 100644 --- a/activesupport/lib/active_support/json/decoding.rb +++ b/activesupport/lib/active_support/json/decoding.rb @@ -43,7 +43,7 @@ module ActiveSupport end if marks.empty? - json + json.gsub(/\\\//, '/') else # FIXME: multiple slow enumerations output = ([0] + marks.map(&:succ)). @@ -51,6 +51,7 @@ module ActiveSupport map { |left, right| json[left..right] }. join(" ") times.each { |i| output[i-1] = ' ' } + output.gsub!(/\\\//, '/') output end end diff --git a/activesupport/lib/active_support/json/encoders/string.rb b/activesupport/lib/active_support/json/encoders/string.rb index 963cd10969..7ddc544294 100644 --- a/activesupport/lib/active_support/json/encoders/string.rb +++ b/activesupport/lib/active_support/json/encoders/string.rb @@ -3,14 +3,15 @@ module ActiveSupport module Encoding ESCAPED_CHARS = { "\010" => '\b', - "\f" => '\f', - "\n" => '\n', - "\r" => '\r', - "\t" => '\t', - '"' => '\"', - '\\' => '\\\\', - ">" => '\076', - '<' => '\074' + "\f" => '\f', + "\n" => '\n', + "\r" => '\r', + "\t" => '\t', + '"' => '\"', + '\\' => '\\\\', + ">" => '\076', + '<' => '\074', + '/' => '\\/' } end end @@ -18,7 +19,7 @@ end class String def to_json(options = nil) #:nodoc: - '"' + gsub(/[\010\f\n\r\t"\\><]/) { |s| + '"' + gsub(/[\010\f\n\r\t"\\><\/]/) { |s| ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] }.gsub(/([\xC0-\xDF][\x80-\xBF]| [\xE0-\xEF][\x80-\xBF]{2}| |