diff options
author | Brett Carter <brett@janrain.com> | 2012-12-13 15:52:19 -0800 |
---|---|---|
committer | Steve Klabnik <steve@steveklabnik.com> | 2012-12-14 20:09:56 -0500 |
commit | 815a9431ab61376a7e8e1bdff21f87bc557992f8 (patch) | |
tree | e626d31f78a9d842a0c096499807e0570e019dae /activesupport/lib/active_support/json/encoding.rb | |
parent | 9c581d3811f6fba6d3d222896b017e783b6e497a (diff) | |
download | rails-815a9431ab61376a7e8e1bdff21f87bc557992f8.tar.gz rails-815a9431ab61376a7e8e1bdff21f87bc557992f8.tar.bz2 rails-815a9431ab61376a7e8e1bdff21f87bc557992f8.zip |
Remove unicode character encoding from ActiveSupport::JSON.encode
The encoding scheme (e.g. ☠ -> "\u2620") was broken for characters
not in the Basic Multilingual Plane. It is possible to escape them
for json using the weird encoding scheme of a twelve-character
sequence representing the UTF-16 surrogate pair (e.g. '𠜎' ->
"\u270e\u263a") but this wasn't properly handled in the escaping code.
Since raw UTF-8 is allowed in json, it was decided to simply pass
through the raw bytes rather than attempt to escape them.
Backport of https://github.com/zbskii/rails/commit/9ace3a8820a5270f9b3f37b593f8bbea3e940f73
Conflicts:
activesupport/CHANGELOG.md
activesupport/lib/active_support/json/encoding.rb
activesupport/test/json/encoding_test.rb
Diffstat (limited to 'activesupport/lib/active_support/json/encoding.rb')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index bd2f909ca9..a50e6524c6 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -122,13 +122,7 @@ module ActiveSupport if string.respond_to?(:force_encoding) string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY) end - json = string. - gsub(escape_regex) { |s| ESCAPED_CHARS[s] }. - gsub(/([\xC0-\xDF][\x80-\xBF]| - [\xE0-\xEF][\x80-\xBF]{2}| - [\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s| - s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&') - } + json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] } json = %("#{json}") json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding) json |