aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller/html-scanner/sanitizer_test.rb
diff options
context:
space:
mode:
authorJeffrey Hardy <packagethief@gmail.com>2008-10-22 16:03:21 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2008-10-23 19:16:12 -0700
commit1a1822726189f3cfff305dea62e5cfbdbc0da577 (patch)
tree493e7103122ccca2883aab36abb053cd6b625172 /actionpack/test/controller/html-scanner/sanitizer_test.rb
parent838cb1aa507746b3562931bb63cf4f474363e17a (diff)
downloadrails-1a1822726189f3cfff305dea62e5cfbdbc0da577.tar.gz
rails-1a1822726189f3cfff305dea62e5cfbdbc0da577.tar.bz2
rails-1a1822726189f3cfff305dea62e5cfbdbc0da577.zip
Fix that HTML::Node.parse would blow up on unclosed CDATA sections.
If an unclosed CDATA section is encountered and parsing is strict, an exception will be raised. Otherwise, we consider the remainder of the line to be the section contents. This is consistent with HTML::Tokenizer#scan_tag. Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/test/controller/html-scanner/sanitizer_test.rb')
-rw-r--r--actionpack/test/controller/html-scanner/sanitizer_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/actionpack/test/controller/html-scanner/sanitizer_test.rb b/actionpack/test/controller/html-scanner/sanitizer_test.rb
index db142f0bc6..a9e8447e32 100644
--- a/actionpack/test/controller/html-scanner/sanitizer_test.rb
+++ b/actionpack/test/controller/html-scanner/sanitizer_test.rb
@@ -17,6 +17,8 @@ class SanitizerTest < Test::Unit::TestCase
%{This is a test.\n\n\nIt no longer contains any HTML.\n}, sanitizer.sanitize(
%{<title>This is <b>a <a href="" target="_blank">test</a></b>.</title>\n\n<!-- it has a comment -->\n\n<p>It no <b>longer <strong>contains <em>any <strike>HTML</strike></em>.</strong></b></p>\n}))
assert_equal "This has a here.", sanitizer.sanitize("This has a <!-- comment --> here.")
+ assert_equal "This has a here.", sanitizer.sanitize("This has a <![CDATA[<section>]]> here.")
+ assert_equal "This has an unclosed ", sanitizer.sanitize("This has an unclosed <![CDATA[<section>]] here...")
[nil, '', ' '].each { |blank| assert_equal blank, sanitizer.sanitize(blank) }
end
@@ -243,6 +245,14 @@ class SanitizerTest < Test::Unit::TestCase
assert_sanitized %(<img src='vbscript:msgbox("XSS")' />), '<img />'
end
+ def test_should_sanitize_cdata_section
+ assert_sanitized "<![CDATA[<span>section</span>]]>", "&lt;![CDATA[&lt;span>section&lt;/span>]]>"
+ end
+
+ def test_should_sanitize_unterminated_cdata_section
+ assert_sanitized "<![CDATA[<span>neverending...", "&lt;![CDATA[&lt;span>neverending...]]>"
+ end
+
protected
def assert_sanitized(input, expected = nil)
@sanitizer ||= HTML::WhiteListSanitizer.new