aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorBrett Carter <brett@janrain.com>2012-12-13 15:52:19 -0800
committerSteve Klabnik <steve@steveklabnik.com>2012-12-14 18:54:32 -0500
commit8f8397e0a4ea2bbc27d4bba60088286217314807 (patch)
tree0c5bc9559b1028a2c4a2df36ddb59171d2bd1257 /activesupport/lib/active_support/json
parentf447240b0565fa48f0dbe9341a7bb0feff938dab (diff)
downloadrails-8f8397e0a4ea2bbc27d4bba60088286217314807.tar.gz
rails-8f8397e0a4ea2bbc27d4bba60088286217314807.tar.bz2
rails-8f8397e0a4ea2bbc27d4bba60088286217314807.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.
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb8
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 7a5c351ca8..832d1ce6d5 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -129,13 +129,7 @@ module ActiveSupport
def escape(string)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
- 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)
json