Skip to content

Commit

Permalink
Patched HTML::Document#initialize call to Node.parse so that it inclu…
Browse files Browse the repository at this point in the history
…des the strict argument. [#330 state:resolved]
  • Loading branch information
jimmybaker authored and jeremy committed Jun 25, 2008
1 parent 6051249 commit 02ffbc2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -17,7 +17,7 @@ def initialize(text, strict=false, xml=false)
@root = Node.new(nil)
node_stack = [ @root ]
while token = tokenizer.next
node = Node.parse(node_stack.last, tokenizer.line, tokenizer.position, token)
node = Node.parse(node_stack.last, tokenizer.line, tokenizer.position, token, strict)

node_stack.last.children << node unless node.tag? && node.closing == :close
if node.tag?
Expand Down
25 changes: 25 additions & 0 deletions actionpack/test/controller/html-scanner/document_test.rb
Expand Up @@ -120,4 +120,29 @@ def test_find_empty_tag
assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => "")
assert doc.find(:tag => "div", :attributes => { :id => "map" }, :content => nil)
end

def test_parse_invalid_document
assert_nothing_raised do
doc = HTML::Document.new("<html>
<table>
<tr>
<td style=\"color: #FFFFFF; height: 17px; onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" style=\"cursor:pointer; height: 17px;\"; nowrap onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" onmouseout=\"this.bgColor='#0066cc'; this.style.color='#FFFFFF'\" onmouseover=\"this.bgColor='#ffffff'; this.style.color='#0033cc'\">About Us</td>
</tr>
</table>
</html>")
end
end

def test_invalid_document_raises_exception_when_strict
assert_raises RuntimeError do
doc = HTML::Document.new("<html>
<table>
<tr>
<td style=\"color: #FFFFFF; height: 17px; onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" style=\"cursor:pointer; height: 17px;\"; nowrap onclick=\"window.location.href='http://www.rmeinc.com/about_rme.aspx'\" onmouseout=\"this.bgColor='#0066cc'; this.style.color='#FFFFFF'\" onmouseover=\"this.bgColor='#ffffff'; this.style.color='#0033cc'\">About Us</td>
</tr>
</table>
</html>", true)
end
end

end

0 comments on commit 02ffbc2

Please sign in to comment.