aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/encoding.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-06-08 15:16:47 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-06-08 15:16:47 -0700
commit30a3b6b4fc56390eec762c879644c95cd09622b0 (patch)
tree167fbfd40a2d2d89c91fb1c9047ad264a670b336 /activesupport/lib/active_support/json/encoding.rb
parentd3078b540ed154b6ea245de40e8de8bba642cd02 (diff)
downloadrails-30a3b6b4fc56390eec762c879644c95cd09622b0.tar.gz
rails-30a3b6b4fc56390eec762c879644c95cd09622b0.tar.bz2
rails-30a3b6b4fc56390eec762c879644c95cd09622b0.zip
Ruby 1.9: fix json encoding
Diffstat (limited to 'activesupport/lib/active_support/json/encoding.rb')
-rw-r--r--activesupport/lib/active_support/json/encoding.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 97e573f7a6..907094a747 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -1,3 +1,4 @@
+# encoding: binary
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/instance_variables'
@@ -88,8 +89,8 @@ module ActiveSupport
end
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.force_encoding('ascii-8bit') if respond_to?(:force_encoding)
json.gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|
[\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|