Skip to content

Commit

Permalink
Fix support for element_children in document fragments.
Browse files Browse the repository at this point in the history
libxml2 doesn't support finding children in document fragments, but I don't
think there's a good reason for this. Bug and proposed patch for libxml2 here:

https://bugzilla.gnome.org/show_bug.cgi?id=733900
  • Loading branch information
Kyle VanderBeek committed Jul 29, 2014
1 parent 983ff1f commit 1793a5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ports/patches/libxml2/0012-Frag-element-children.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/tree.c.orig 2012-05-14 19:39:20.000000000 -0700
+++ b/tree.c 2014-07-29 13:01:58.000000000 -0700
@@ -3438,6 +3438,7 @@
case XML_ELEMENT_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_NODE:
+ case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
cur = parent->children;
break;
@@ -3473,6 +3474,7 @@
case XML_ELEMENT_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_NODE:
+ case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
cur = parent->children;
break;
@@ -3508,6 +3510,7 @@
case XML_ELEMENT_NODE:
case XML_ENTITY_NODE:
case XML_DOCUMENT_NODE:
+ case XML_DOCUMENT_FRAG_NODE:
case XML_HTML_DOCUMENT_NODE:
cur = parent->last;
break;
5 changes: 5 additions & 0 deletions test/html/test_document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def test_fragment_with_comment
fragment.to_s)
end

def test_element_children_counts
doc = Nokogiri::HTML::DocumentFragment.parse(" <div> </div>\n ")
assert doc.element_children.count == 1
end

def test_malformed_fragment_is_corrected
fragment = HTML::DocumentFragment.parse("<div </div>")
assert_equal "<div></div>", fragment.to_s
Expand Down

0 comments on commit 1793a5a

Please sign in to comment.