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

Changeset 4911

Show
Ignore:
Timestamp:
09/03/06 00:02:14 (2 years ago)
Author:
rick
Message:

Update sanitize text helper to strip plaintext tags, and <img src=javascript:bang>. [Rick Olson]

Files:

Legend:

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

    r4908 r4911  
    11*SVN* 
     2 
     3* Update sanitize text helper to strip plaintext tags, and <img src="javascript:bang">.  [Rick Olson] 
    24 
    35* Update routing documentation.  Closes #6017 [Nathan Witmer] 
  • trunk/actionpack/lib/action_view/helpers/text_helper.rb

    r4896 r4911  
    169169      end 
    170170 
    171       VERBOTEN_TAGS = %w(form script) unless defined?(VERBOTEN_TAGS) 
     171      VERBOTEN_TAGS = %w(form script plaintext) unless defined?(VERBOTEN_TAGS) 
    172172      VERBOTEN_ATTRS = /^on/i unless defined?(VERBOTEN_ATTRS) 
    173173 
     
    193193                  if node.closing != :close 
    194194                    node.attributes.delete_if { |attr,v| attr =~ VERBOTEN_ATTRS } 
    195                     if node.attributes["href"] =~ /^javascript:/i 
    196                       node.attributes.delete "href" 
     195                    %w(href src).each do |attr| 
     196                      node.attributes.delete attr if node.attributes[attr] =~ /^javascript:/i 
    197197                    end 
    198198                  end 
  • trunk/actionpack/test/template/text_helper_test.rb

    r4896 r4911  
    196196  end 
    197197 
     198  def test_sanitize_plaintext 
     199    raw = "<plaintext><span>foo</span></plaintext>" 
     200    result = sanitize(raw) 
     201    assert_equal "&lt;plaintext><span>foo</span>&lt;/plaintext>", result 
     202  end 
     203 
    198204  def test_sanitize_script 
    199205    raw = "<script language=\"Javascript\">blah blah blah</script>" 
     
    212218    result = sanitize(raw) 
    213219    assert_equal %{href="javascript:bang" <a name='hello'>foo</a>, <span>bar</span>}, result 
     220  end 
     221   
     222  def test_sanitize_image_src 
     223    raw = %{src="javascript:bang" <img src="javascript:bang" width="5">foo</img>, <span src="javascript:bang">bar</span>} 
     224    result = sanitize(raw) 
     225    assert_equal %{src="javascript:bang" <img width='5'>foo</img>, <span>bar</span>}, result 
    214226  end 
    215227