Skip to content

Instantly share code, notes, and snippets.

@wyattisimo
Created September 11, 2014 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyattisimo/534f5138c084f11bbc30 to your computer and use it in GitHub Desktop.
Save wyattisimo/534f5138c084f11bbc30 to your computer and use it in GitHub Desktop.
unicode patch
module ActiveSupport::JSON::Encoding
def self.escape(string)
if string.respond_to?(:force_encoding)
string = string.encode(::Encoding::UTF_8, :undef => :replace).force_encoding(::Encoding::BINARY)
end
json = string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] }
json = %("#{json}")
json.force_encoding(::Encoding::UTF_8) if json.respond_to?(:force_encoding)
json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment