Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
04/08/08 03:45:26 (4 months ago)
Author:
rick
Message:

Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick]

Files:

Legend:

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

    r9203 r9238  
    1 require 'active_support/json/encoding' 
    2 require 'active_support/json/decoding' 
     1 
    32 
    43module ActiveSupport 
     4  # If true, use ISO 8601 format for dates and times.  Otherwise, fall back to the ActiveSupport legacy format. 
    55  mattr_accessor :use_standard_json_time_format 
     6 
     7  class << self 
     8    def escape_html_entities_in_json 
     9      @escape_html_entities_in_json 
     10    end 
     11 
     12    def escape_html_entities_in_json=(value) 
     13      ActiveSupport::JSON::Encoding.escape_regex = \ 
     14        if value 
     15          /[\010\f\n\r\t"\\><&]/ 
     16        else 
     17          /[\010\f\n\r\t"\\]/ 
     18        end 
     19      @escape_html_entities_in_json = value 
     20    end 
     21  end 
    622 
    723  module JSON 
     
    3248  end 
    3349end 
     50 
     51require 'active_support/json/encoding' 
     52require 'active_support/json/decoding' 
  • trunk/activesupport/lib/active_support/json/encoders/string.rb

    r9138 r9238  
    22  module JSON 
    33    module Encoding 
     4      mattr_accessor :escape_regex 
     5 
    46      ESCAPED_CHARS = { 
    57        "\010" =>  '\b', 
     
    1820end 
    1921 
     22ActiveSupport.escape_html_entities_in_json = true 
     23 
    2024class String 
    2125  def to_json(options = nil) #:nodoc: 
    22     json = '"' + gsub(/[\010\f\n\r\t"\\><&]/) { |s| 
     26    json = '"' + gsub(ActiveSupport::JSON::Encoding.escape_regex) { |s| 
    2327      ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 
    2428    } 
  • trunk/activesupport/lib/active_support/json/encoding.rb

    r7736 r9238  
    11require 'active_support/json/variable' 
    2  
    32require 'active_support/json/encoders/object' # Require explicitly for rdoc. 
    43Dir["#{File.dirname(__FILE__)}/encoders/**/*.rb"].each do |file|