From 30a3b6b4fc56390eec762c879644c95cd09622b0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 8 Jun 2009 15:16:47 -0700 Subject: Ruby 1.9: fix json encoding --- activesupport/lib/active_support/json/encoding.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') 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| -- cgit v1.2.3