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

Changeset 7506

Show
Ignore:
Timestamp:
09/17/07 21:37:48 (1 year ago)
Author:
bitsweat
Message:

Fix JSON decoder with nested quotes and commas. Closes #9579.

Files:

Legend:

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

    r7505 r7506  
    11*SVN* 
     2 
     3* Fix JSON decoder with nested quotes and commas.  #9579 [zdennis] 
    24 
    35* Hash#to_xml doesn't double-unescape.  #8806 [Ezran] 
  • trunk/activesupport/lib/active_support/json/decoding.rb

    r6443 r7506  
    1616       
    1717      protected 
     18         
    1819        # Ensure that ":" and "," are always followed by a space 
    1920        def convert_json_to_yaml(json) #:nodoc: 
    2021          scanner, quoting, marks = StringScanner.new(json), false, [] 
    2122 
    22           while scanner.scan_until(/(['":,]|\\.)/) 
     23          while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/) 
    2324            case char = scanner[1] 
    2425            when '"', "'" 
    25               quoting = quoting == char ? false : char 
    26             when ":", "," 
     26              if !quoting 
     27                quoting = char 
     28              elsif quoting == char 
     29                quoting = false 
     30              end 
     31            when ":","," 
    2732              marks << scanner.pos - 1 unless quoting 
    2833            end 
    2934          end 
    30            
     35 
    3136          if marks.empty? 
    3237            json 
  • trunk/activesupport/test/json/decoding_test.rb

    r7117 r7506  
    99    %({"returnTo":[1,"a"]})                    => {"returnTo" => [1, "a"]}, 
    1010    %({"returnTo":[1,"\\"a\\",", "b"]})        => {"returnTo" => [1, "\"a\",", "b"]}, 
     11    %({a: "'", "b": "5,000"})     => {"a" => "'", "b" => "5,000"}, 
     12    %({a: "a's, b's and c's", "b": "5,000"})     => {"a" => "a's, b's and c's", "b" => "5,000"}, 
    1113    %([])    => [], 
    1214    %({})    => {},