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

Changeset 5322

Show
Ignore:
Timestamp:
10/18/06 16:42:19 (2 years ago)
Author:
rick
Message:

Add <%= escape_once html %> to escape html while leaving any currently escaped entities alone. Fix button_to double-escaping issue. [Rick]

Files:

Legend:

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

    r5321 r5322  
    11*SVN* 
     2 
     3* Add <%= escape_once html %> to escape html while leaving any currently escaped entities alone.  Fix button_to double-escaping issue. [Rick] 
    24 
    35* Fix double-escaped entities, such as &amp;amp;, &amp;#123;, etc. [Rick] 
  • trunk/actionpack/lib/action_view/helpers/tag_helper.rb

    r5321 r5322  
    3232      end 
    3333 
     34      # Escapes a given string, while leaving any currently escaped entities alone. 
     35      # 
     36      #   escape_once("1 > 2 &amp; 3") 
     37      #   # => "1 &lt; 2 &amp; 3" 
     38      # 
     39      def escape_once(html) 
     40        fix_double_escape(html_escape(html.to_s)) 
     41      end 
     42 
    3443      private 
    3544        def tag_options(options) 
    3645          cleaned_options = convert_booleans(options.stringify_keys.reject {|key, value| value.nil?}) 
    37           ' ' + cleaned_options.map {|key, value| %(#{key}="#{fix_double_escape(html_escape(value.to_s))}")}.sort * ' ' unless cleaned_options.empty? 
     46          ' ' + cleaned_options.map {|key, value| %(#{key}="#{escape_once(value)}")}.sort * ' ' unless cleaned_options.empty? 
    3847        end 
    3948 
  • trunk/actionpack/lib/action_view/helpers/url_helper.rb

    r4914 r5322  
    132132 
    133133        html_options.merge!("type" => "submit", "value" => name) 
    134  
    135         "<form method=\"#{form_method}\" action=\"#{h url}\" class=\"button-to\"><div>" +  
     134         
     135        "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +  
    136136          method_tag + tag("input", html_options) + "</div></form>" 
    137137      end 
  • trunk/actionpack/test/template/tag_helper_test.rb

    r5321 r5322  
    4040  end 
    4141   
     42  def test_escape_once 
     43    assert_equal '1 &lt; 2 &amp; 3', escape_once('1 < 2 &amp; 3') 
     44  end 
     45   
    4246  def test_double_escaping_attributes 
    4347    ['1&amp;2', '1 &lt; 2', '&#8220;test&#8220;'].each do |escaped| 
  • trunk/actionpack/test/template/url_helper_test.rb

    r4914 r5322  
    3737  def test_button_to_with_query 
    3838    assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&q2=v2") 
     39  end 
     40 
     41  def test_button_to_with_escaped_query 
     42    assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&amp;q2=v2") 
    3943  end 
    4044