diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-01 20:36:53 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-01 20:36:53 -0300 |
commit | 084e4a2dd4322c9ea748a426cb37bf90ab83613d (patch) | |
tree | 90c6130b3f8becfd733618752a0649e932f5d514 /activesupport/lib/active_support/json | |
parent | 260c847817bbc3ad990609b7e41f787e1d2940ea (diff) | |
parent | 92bff2ebf122252cf3ff64160bdfa9891fcff3f4 (diff) | |
download | rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.tar.gz rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.tar.bz2 rails-084e4a2dd4322c9ea748a426cb37bf90ab83613d.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 068b58b997..f440d6ce58 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -1,5 +1,7 @@ -# encoding: binary +# encoding: utf-8 require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/object/instance_variables' require 'active_support/deprecation' @@ -95,12 +97,14 @@ module ActiveSupport def escape(string) string = string.dup.force_encoding(::Encoding::BINARY) if string.respond_to?(:force_encoding) - json = '"' + string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] } - json.gsub(/([\xC0-\xDF][\x80-\xBF]| + 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}/, '\\\\u\&') - } + '"' + s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&') + } + %("#{json}") end end |