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

Changeset 5321

Show
Ignore:
Timestamp:
10/18/06 15:58:07 (2 years ago)
Author:
rick
Message:

Fix double-escaped entities, such as &, {, etc. [Rick]

Files:

Legend:

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

    r5315 r5321  
    11*SVN* 
     2 
     3* Fix double-escaped entities, such as &, {, etc. [Rick] 
    24 
    35* Fix deprecation warnings when rendering the template error template. [Nicholas Seckar] 
  • trunk/actionpack/lib/action_view/helpers/tag_helper.rb

    r2543 r5321  
    3535        def tag_options(options) 
    3636          cleaned_options = convert_booleans(options.stringify_keys.reject {|key, value| value.nil?}) 
    37           ' ' + cleaned_options.map {|key, value| %(#{key}="#{html_escape(value.to_s)}")}.sort * ' ' unless cleaned_options.empty? 
     37          ' ' + cleaned_options.map {|key, value| %(#{key}="#{fix_double_escape(html_escape(value.to_s))}")}.sort * ' ' unless cleaned_options.empty? 
    3838        end 
    3939 
     
    4646          options[attribute] ? options[attribute] = attribute : options.delete(attribute) 
    4747        end 
     48         
     49        # Fix double-escaped entities, such as &, {, etc. 
     50        def fix_double_escape(escaped) 
     51          escaped.gsub(/&([a-z]+|(#\d+));/i) { "&#{$1};" } 
     52        end 
    4853    end 
    4954  end 
  • trunk/actionpack/test/template/tag_helper_test.rb

    r4675 r5321  
    3939    assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>") 
    4040  end 
     41   
     42  def test_double_escaping_attributes 
     43    ['1&amp;2', '1 &lt; 2', '&#8220;test&#8220;'].each do |escaped| 
     44      assert_equal %(<a href="#{escaped}" />), tag('a', :href => escaped) 
     45    end 
     46  end 
     47   
     48  def test_skip_invalid_escaped_attributes 
     49    ['&1;', '&#1dfa3;', '& #123;'].each do |escaped| 
     50      assert_equal %(<a href="#{escaped.gsub /&/, '&amp;'}" />), tag('a', :href => escaped) 
     51    end 
     52  end 
    4153end