Sha256: e5a9607e7b225635371c20cf43143ece40d4f5dad0163ac451c19f2272a896d1

Contents?: true

Size: 934 Bytes

Versions: 42

Compression:

Stored size: 934 Bytes

Contents

module ActiveSupport
  module JSON
    module Encoding
      mattr_accessor :escape_regex

      ESCAPED_CHARS = {
        "\010" =>  '\b',
        "\f"   =>  '\f',
        "\n"   =>  '\n',
        "\r"   =>  '\r',
        "\t"   =>  '\t',
        '"'    =>  '\"',
        '\\'   =>  '\\\\',
        '>'    =>  '\u003E',
        '<'    =>  '\u003C',
        '&'    =>  '\u0026'
      }
    end
  end
end

ActiveSupport.escape_html_entities_in_json = true

class String
  def to_json(options = nil) #:nodoc:
    json = '"' + gsub(ActiveSupport::JSON::Encoding.escape_regex) { |s|
      ActiveSupport::JSON::Encoding::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|
      s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&')
    } + '"'
  end
end

Version data entries

42 entries across 41 versions & 14 rubygems

Version Path
3mix-castronaut-0.5.0.2 vendor/activesupport/lib/active_support/json/encoders/string.rb
masover-castronaut-0.4.4.4 vendor/activesupport/lib/active_support/json/encoders/string.rb
masover-castronaut-0.4.4.5 vendor/activesupport/lib/active_support/json/encoders/string.rb
masover-castronaut-0.5.0.1 vendor/activesupport/lib/active_support/json/encoders/string.rb
p8-castronaut-0.6.1.1 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.1 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.2 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.3 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.4 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.5 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.4.6 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.5.0 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.5.1 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.5.2 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.5.3 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.5.4 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.6.0 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.6.1 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.7.4 vendor/activesupport/lib/active_support/json/encoders/string.rb
relevance-castronaut-0.7.5 vendor/activesupport/lib/active_support/json/encoders/string.rb