Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[html-scanner] Fix parsing of empty tags. Closes #7641. [anthony.bailey]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7528 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9b468f4cd7daa9f1e8122938e6c2c5b8bf235a5f 1 parent 4e0fef4
Michael Koziarski NZKoz authored
3  actionpack/lib/action_controller/vendor/html-scanner/html/document.rb
View
@@ -22,6 +22,9 @@ def initialize(text, strict=false, xml=false)
if node.tag?
if node_stack.length > 1 && node.closing == :close
if node_stack.last.name == node.name
+ if node_stack.last.children.empty?
+ node_stack.last.children << Text.new(node_stack.last, node.line, node.position, "")
+ end
node_stack.pop
else
open_start = node_stack.last.position - 20
20 actionpack/test/controller/html-scanner/document_test.rb
View
@@ -75,6 +75,26 @@ def test_parse_document
assert_not_nil doc.find(:tag => "div", :children => { :count => 1, :only => { :tag => "table" } })
end
+ def test_tag_nesting_nothing_to_s
+ doc = HTML::Document.new("<tag></tag>")
+ assert_equal "<tag></tag>", doc.root.to_s
+ end
+
+ def test_tag_nesting_space_to_s
+ doc = HTML::Document.new("<tag> </tag>")
+ assert_equal "<tag> </tag>", doc.root.to_s
+ end
+
+ def test_tag_nesting_text_to_s
+ doc = HTML::Document.new("<tag>text</tag>")
+ assert_equal "<tag>text</tag>", doc.root.to_s
+ end
+
+ def test_tag_nesting_tag_to_s
+ doc = HTML::Document.new("<tag><nested /></tag>")
+ assert_equal "<tag><nested /></tag>", doc.root.to_s
+ end
+
def test_parse_cdata
doc = HTML::Document.new(<<-HTML)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Please sign in to comment.
Something went wrong with that request. Please try again.