Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ruby 1.9: fix json encoding

  • Loading branch information...
commit 30a3b6b4fc56390eec762c879644c95cd09622b0 1 parent d3078b5
@jeremy jeremy authored
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/array/wrap'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/instance_variables'
@@ -88,8 +89,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|
Please sign in to comment.
Something went wrong with that request. Please try again.