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

Changeset 8050

Show
Ignore:
Timestamp:
10/29/07 00:18:43 (1 year ago)
Author:
rick
Message:

Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec. Closes #9975 [josh, chuyeow, tpope]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/test/template/javascript_helper_test.rb

    r8034 r8050  
    3939      page.replace_html 'header', "<h1>Greetings</h1>" 
    4040    end 
    41     assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\074h1\\076Greetings\\074\\/h1\\076&quot;);; return false;">Greet me!</a>), html 
     41    assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\\/h1\\u003E&quot;);; return false;">Greet me!</a>), html 
    4242  end 
    4343 
     
    4646      page.replace_html 'header', "<h1>Greetings</h1>" 
    4747    end 
    48     assert_dom_equal %(<a href="#" class="updater" onclick="Element.update(&quot;header&quot;, &quot;\\074h1\\076Greetings\\074\\/h1\\076&quot;);; return false;">Greet me!</a>), html 
     48    assert_dom_equal %(<a href="#" class="updater" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\\/h1\\u003E&quot;);; return false;">Greet me!</a>), html 
    4949  end 
    5050 
     
    6868      page.replace_html 'header', "<h1>Greetings</h1>" 
    6969    end 
    70     assert_dom_equal %(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\\074h1\\076Greetings\\074\\/h1\\076&quot;);;" value="Greet me!" />), html 
     70    assert_dom_equal %(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\\/h1\\u003E&quot;);;" value="Greet me!" />), html 
    7171  end 
    7272 
     
    7575      page.replace_html 'header', "<h1>Greetings</h1>" 
    7676    end 
    77     assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\\074h1\\076Greetings\\074\\/h1\\076&quot;);;" value="Greet me!" />), html 
     77    assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\\/h1\\u003E&quot;);;" value="Greet me!" />), html 
    7878  end 
    7979 
  • trunk/actionpack/test/template/prototype_helper_test.rb

    r8034 r8050  
    304304   
    305305  def test_insert_html_with_string 
    306     assert_equal 'new Insertion.Top("element", "\\074p\\076This is a test\\074\\/p\\076");', 
     306    assert_equal 'new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E");', 
    307307      @generator.insert_html(:top, 'element', '<p>This is a test</p>') 
    308     assert_equal 'new Insertion.Bottom("element", "\\074p\076This is a test\\074\\/p\076");', 
     308    assert_equal 'new Insertion.Bottom("element", "\\u003Cp\u003EThis is a test\\u003C\\/p\u003E");', 
    309309      @generator.insert_html(:bottom, 'element', '<p>This is a test</p>') 
    310     assert_equal 'new Insertion.Before("element", "\\074p\076This is a test\\074\\/p\076");', 
     310    assert_equal 'new Insertion.Before("element", "\\u003Cp\u003EThis is a test\\u003C\\/p\u003E");', 
    311311      @generator.insert_html(:before, 'element', '<p>This is a test</p>') 
    312     assert_equal 'new Insertion.After("element", "\\074p\076This is a test\\074\\/p\076");', 
     312    assert_equal 'new Insertion.After("element", "\\u003Cp\u003EThis is a test\\u003C\\/p\u003E");', 
    313313      @generator.insert_html(:after, 'element', '<p>This is a test</p>') 
    314314  end 
    315315   
    316316  def test_replace_html_with_string 
    317     assert_equal 'Element.update("element", "\\074p\\076This is a test\\074\\/p\\076");', 
     317    assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E");', 
    318318      @generator.replace_html('element', '<p>This is a test</p>') 
    319319  end 
    320320   
    321321  def test_replace_element_with_string 
    322     assert_equal 'Element.replace("element", "\\074div id=\"element\"\\076\\074p\\076This is a test\\074\\/p\\076\\074\\/div\\076");', 
     322    assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E\\u003C\\/div\\u003E");', 
    323323      @generator.replace('element', '<div id="element"><p>This is a test</p></div>') 
    324324  end 
     
    376376     
    377377    assert_equal <<-EOS.chomp, @generator.to_s 
    378 new Insertion.Top("element", "\\074p\\076This is a test\\074\\/p\\076"); 
    379 new Insertion.Bottom("element", "\\074p\\076This is a test\\074\\/p\\076"); 
     378new Insertion.Top("element", "\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E"); 
     379new Insertion.Bottom("element", "\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E"); 
    380380["foo", "bar"].each(Element.remove); 
    381 Element.update("baz", "\\074p\\076This is a test\\074\\/p\\076"); 
     381Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C\\/p\\u003E"); 
    382382    EOS 
    383383  end 
  • trunk/activerecord/test/serialization_test.rb

    r7519 r8050  
    1212      :created_at  => Time.utc(2006, 8, 1), 
    1313      :awesome     => false, 
    14       :preferences => { :gem => 'ruby' } 
     14      :preferences => { :gem => '<strong>ruby</strong>' } 
    1515    } 
    1616 
  • trunk/activesupport/CHANGELOG

    r8026 r8050  
    11*SVN* 
     2 
     3* Change JSON to encode %w(< > &) as 4 digit hex codes to be in compliance with the JSON spec.  Closes #9975 [josh, chuyeow, tpope] 
    24 
    35* Fix JSON encoding/decoding bugs dealing with /'s.  Closes #9990 [Rick, theamazingrando] 
  • trunk/activesupport/lib/active_support/json/encoders/string.rb

    r8026 r8050  
    1010        '"'    =>  '\"', 
    1111        '\\'   =>  '\\\\', 
    12         ">"    =>  '\076', 
    13         '<'    =>  '\074', 
     12        '>'    =>  '\u003E', 
     13        '<'    =>  '\u003C', 
     14        '&'    =>  '\u0026', 
    1415        '/'    =>  '\\/' 
    1516      } 
     
    2021class String 
    2122  def to_json(options = nil) #:nodoc: 
    22     '"' + gsub(/[\010\f\n\r\t"\\><\/]/) { |s| 
     23    '"' + gsub(/[\010\f\n\r\t"\\><&\/]/) { |s| 
    2324      ActiveSupport::JSON::Encoding::ESCAPED_CHARS[s] 
    2425    }.gsub(/([\xC0-\xDF][\x80-\xBF]| 
  • trunk/activesupport/test/json/encoding_test.rb

    r8026 r8050  
    1414                   [ 2.5,   %(2.5)   ]] 
    1515 
    16   StringTests   = [[ 'this is the <string>',     %("this is the \\074string\\076")], 
    17                    [ 'a "string" with quotes', %("a \\"string\\" with quotes") ], 
     16  StringTests   = [[ 'this is the <string>',     %("this is the \\u003Cstring\\u003E")], 
     17                   [ 'a "string" with quotes & an ampersand', %("a \\"string\\" with quotes \\u0026 an ampersand") ], 
    1818                   [ 'http://test.host/posts/1', %("http:\\/\\/test.host\\/posts\\/1")]] 
    1919