From c708346688ee3cdd5583795ccd9b10590abd36b1 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Mon, 29 Oct 2007 00:18:43 +0000 Subject: Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec. Closes #9975 [josh, chuyeow, tpope] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8050 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/json/encoders/string.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/json/encoders') diff --git a/activesupport/lib/active_support/json/encoders/string.rb b/activesupport/lib/active_support/json/encoders/string.rb index 7ddc544294..ca74436802 100644 --- a/activesupport/lib/active_support/json/encoders/string.rb +++ b/activesupport/lib/active_support/json/encoders/string.rb @@ -9,8 +9,9 @@ module ActiveSupport "\t" => '\t', '"' => '\"', '\\' => '\\\\', - ">" => '\076', - '<' => '\074', + '>' => '\u003E', + '<' => '\u003C', + '&' => '\u0026', '/' => '\\/' } end @@ -19,7 +20,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}| -- cgit v1.2.3