Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6893

Show
Ignore:
Timestamp:
05/29/07 09:10:36 (1 year ago)
Author:
rick
Message:

escape <'s and >'s in JSON strings. #8371 [Rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r6886 r6893  
    11*SVN* 
     2 
     3* escape <'s and >'s in JSON strings. #8371 [Rick] 
    24 
    35* Inflections: MatrixTest -> MatrixTests instead of MatricesTest.  #8496 [jbwiv] 
  • trunk/activesupport/lib/active_support/json/encoders/string.rb

    r6443 r6893  
    99        "\t" =>    '\t', 
    1010        '"' =>     '\"', 
    11         '\\' =>    '\\\\' 
     11        '\\' =>    '\\\\', 
     12        ">" =>     '\076', 
     13        '<' =>     '\074' 
    1214      } 
    1315    end 
     
    1719class String 
    1820  def to_json #:nodoc: 
    19     '"' + gsub(/[\010\f\n\r\t"\\]/) { |s| 
     21    '"' + gsub(/[\010\f\n\r\t"\\><]/) { |s| 
    2022      ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 
    2123    }.gsub(/([\xC0-\xDF][\x80-\xBF]| 
  • trunk/activesupport/test/json/encoding_test.rb

    r6822 r6893  
    1414                   [ 2.5,   %(2.5)   ]] 
    1515 
    16   StringTests   = [[ 'this is the string',     %("this is the string")         ], 
     16  StringTests   = [[ 'this is the <string>',     %("this is the \\074string\\076")], 
    1717                   [ 'a "string" with quotes', %("a \\"string\\" with quotes") ]] 
    1818