Browse files

Ruby 1.9: fix json encoding

  • Loading branch information...
1 parent 01f820c commit ec10f13939fd3b91f863878cc5aae740c67f6def @jeremy jeremy committed Jun 8, 2009
Showing with 2 additions and 1 deletion.
  1. +2 −1 activesupport/lib/active_support/json/encoding.rb
View
3 activesupport/lib/active_support/json/encoding.rb
@@ -1,3 +1,4 @@
+# encoding: binary
require 'active_support/core_ext/module/delegation'
require 'active_support/deprecation'
@@ -49,8 +50,8 @@ def escape_html_entities_in_json=(value)
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|

0 comments on commit ec10f13

Please sign in to comment.