Changeset 9238
- Timestamp:
- 04/08/08 03:45:26 (8 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/json.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/json/encoders/string.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/json/encoding.rb (modified) (1 diff)
- trunk/activesupport/test/json/encoding_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9227 r9238 1 1 *SVN* 2 3 * Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick] 2 4 3 5 * Improve documentation. [Xavier Noria] trunk/activesupport/lib/active_support/json.rb
r9203 r9238 1 require 'active_support/json/encoding' 2 require 'active_support/json/decoding' 1 3 2 4 3 module ActiveSupport 4 # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the ActiveSupport legacy format. 5 5 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 6 22 7 23 module JSON … … 32 48 end 33 49 end 50 51 require 'active_support/json/encoding' 52 require 'active_support/json/decoding' trunk/activesupport/lib/active_support/json/encoders/string.rb
r9138 r9238 2 2 module JSON 3 3 module Encoding 4 mattr_accessor :escape_regex 5 4 6 ESCAPED_CHARS = { 5 7 "\010" => '\b', … … 18 20 end 19 21 22 ActiveSupport.escape_html_entities_in_json = true 23 20 24 class String 21 25 def to_json(options = nil) #:nodoc: 22 json = '"' + gsub( /[\010\f\n\r\t"\\><&]/) { |s|26 json = '"' + gsub(ActiveSupport::JSON::Encoding.escape_regex) { |s| 23 27 ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 24 28 } trunk/activesupport/lib/active_support/json/encoding.rb
r7736 r9238 1 1 require 'active_support/json/variable' 2 3 2 require 'active_support/json/encoders/object' # Require explicitly for rdoc. 4 3 Dir["#{File.dirname(__FILE__)}/encoders/**/*.rb"].each do |file| trunk/activesupport/test/json/encoding_test.rb
r9203 r9238 39 39 StandardTimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005-02-01T15:15:10Z") ]] 40 40 StandardDateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005-02-01T15:15:10+00:00") ]] 41 StandardStringTests = [[ 'this is the <string>', %("this is the <string>")]] 41 42 42 43 constants.grep(/Tests$/).each do |class_tests| 43 44 define_method("test_#{class_tests[0..-6].underscore}") do 44 45 begin 46 ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/ 45 47 ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/ 46 48 self.class.const_get(class_tests).each do |pair| … … 48 50 end 49 51 ensure 52 ActiveSupport.escape_html_entities_in_json = false 50 53 ActiveSupport.use_standard_json_time_format = false 51 54 end