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
radiant-0.7.2 vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
vibes-bj-1.2.2 spec/rails_root/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
vibes-bj-1.2.1 spec/rails_root/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
nbudin-castronaut-0.7.5 vendor/activesupport/lib/active_support/json/encoders/string.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
usher-0.7.0 spec/rails2_2/vendor/rails/vendor/rails/activesupport/pkg/activesupport-2.2.2/lib/active_support/json/encoders/string.rb
factorylabs-castronaut-0.7.5 vendor/activesupport/lib/active_support/json/encoders/string.rb
activesupport-2.2.3 lib/active_support/json/encoders/string.rb
webroar-0.2.2 src/admin_panel/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
activesupport-2.1.0 lib/active_support/json/encoders/string.rb
activesupport-2.3.2 lib/active_support/json/encoders/string.rb
activesupport-2.2.2 lib/active_support/json/encoders/string.rb
activesupport-2.1.2 lib/active_support/json/encoders/string.rb
activesupport-2.1.1 lib/active_support/json/encoders/string.rb
antfarm-0.3.0 rails/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
antfarm-0.4.0 rails/vendor/rails/activesupport/lib/active_support/json/encoders/string.rb
mack-active_record-0.8.2 lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/string.rb
mack-facets-0.8.3.1 lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/string.rb
mack-facets-0.8.3 lib/gems/activesupport-2.2.2/lib/active_support/json/encoders/string.rb
radiant-0.7.0 vendor/rails/activesupport/lib/active_support/json/encoders/string.rb