Permalink
Browse files

Force json string encoding to ASCII-8BIT before unpacking for Ruby 1.9.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9138 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 6ef3bc3 commit eece9b4e8a9b46a909af424538c4cc55d78b0142 @josh josh committed Mar 29, 2008
Showing with 4 additions and 2 deletions.
  1. +4 −2 activesupport/lib/active_support/json/encoders/string.rb
@@ -19,9 +19,11 @@ module Encoding
class String
def to_json(options = nil) #:nodoc:
- '"' + gsub(/[\010\f\n\r\t"\\><&]/) { |s|
+ json = '"' + gsub(/[\010\f\n\r\t"\\><&]/) { |s|
ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s]
- }.gsub(/([\xC0-\xDF][\x80-\xBF]|
+ }
+ 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|
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')

0 comments on commit eece9b4

Please sign in to comment.