Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
03/29/08 21:48:08 (6 months ago)
Author:
josh
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/json/encoders/string.rb

    r8255 r9138  
    2020class String 
    2121  def to_json(options = nil) #:nodoc: 
    22     '"' + gsub(/[\010\f\n\r\t"\\><&]/) { |s| 
     22    json = '"' + gsub(/[\010\f\n\r\t"\\><&]/) { |s| 
    2323      ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 
    24     }.gsub(/([\xC0-\xDF][\x80-\xBF]| 
     24    } 
     25    json.force_encoding('ascii-8bit') if respond_to?(:force_encoding) 
     26    json.gsub(/([\xC0-\xDF][\x80-\xBF]| 
    2527             [\xE0-\xEF][\x80-\xBF]{2}| 
    2628             [\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s|