diff options
author | Jeffrey Hardy <packagethief@gmail.com> | 2008-10-22 16:03:21 -0400 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-10-23 19:16:12 -0700 |
commit | 1a1822726189f3cfff305dea62e5cfbdbc0da577 (patch) | |
tree | 493e7103122ccca2883aab36abb053cd6b625172 /actionpack/test/controller/html-scanner/node_test.rb | |
parent | 838cb1aa507746b3562931bb63cf4f474363e17a (diff) | |
download | rails-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/node_test.rb')
-rw-r--r-- | actionpack/test/controller/html-scanner/node_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/actionpack/test/controller/html-scanner/node_test.rb b/actionpack/test/controller/html-scanner/node_test.rb index 240f01ac8b..b0df36877e 100644 --- a/actionpack/test/controller/html-scanner/node_test.rb +++ b/actionpack/test/controller/html-scanner/node_test.rb @@ -65,4 +65,25 @@ class NodeTest < Test::Unit::TestCase assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) } assert node.attributes.has_key?("onmouseover") end + + def test_parse_with_valid_cdata_section + s = "<![CDATA[<span>contents</span>]]>" + node = nil + assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) } + assert_kind_of HTML::CDATA, node + assert_equal '<span>contents</span>', node.content + end + + def test_parse_strict_with_unterminated_cdata_section + s = "<![CDATA[neverending..." + assert_raise(RuntimeError) { HTML::Node.parse(nil,0,0,s) } + end + + def test_parse_relaxed_with_unterminated_cdata_section + s = "<![CDATA[neverending..." + node = nil + assert_nothing_raised { node = HTML::Node.parse(nil,0,0,s,false) } + assert_kind_of HTML::CDATA, node + assert_equal 'neverending...', node.content + end end |