From 1793a5a0fd1dc3b8d1b1dec053deaa8315b719a8 Mon Sep 17 00:00:00 2001 From: Kyle VanderBeek Date: Tue, 29 Jul 2014 12:33:45 -0700 Subject: [PATCH] Fix support for element_children in document fragments. 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 --- .../libxml2/0012-Frag-element-children.patch | 26 +++++++++++++++++++ test/html/test_document_fragment.rb | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 ports/patches/libxml2/0012-Frag-element-children.patch diff --git a/ports/patches/libxml2/0012-Frag-element-children.patch b/ports/patches/libxml2/0012-Frag-element-children.patch new file mode 100644 index 0000000000..5a80e15237 --- /dev/null +++ b/ports/patches/libxml2/0012-Frag-element-children.patch @@ -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; diff --git a/test/html/test_document_fragment.rb b/test/html/test_document_fragment.rb index 0c3550905b..5b9a154a15 100644 --- a/test/html/test_document_fragment.rb +++ b/test/html/test_document_fragment.rb @@ -230,6 +230,11 @@ def test_fragment_with_comment fragment.to_s) end + def test_element_children_counts + doc = Nokogiri::HTML::DocumentFragment.parse("
\n ") + assert doc.element_children.count == 1 + end + def test_malformed_fragment_is_corrected fragment = HTML::DocumentFragment.parse("
") assert_equal "
", fragment.to_s