Skip to content

Commit

Permalink
test and workaround for libxml in-context parsing bug. closes #362.
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Nov 4, 2010
1 parent 63f5967 commit cedc5d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ext/nokogiri/xml_node.c
Expand Up @@ -1171,6 +1171,7 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
{
xmlNodePtr node;
xmlNodePtr list;
xmlNodePtr child_iter;
xmlNodeSetPtr set;
xmlParserErrors error;
VALUE doc, err;
Expand All @@ -1196,6 +1197,14 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
(int)NUM2INT(_options),
&list);

/* make sure parent/child pointers are coherent so an unlink will work properly (#331) */
child_iter = node->doc->children ;
while (child_iter) {
if (child_iter->parent != (xmlNodePtr)node->doc)
child_iter->parent = (xmlNodePtr)node->doc ;
child_iter = child_iter->next ;
}

#ifndef HTML_PARSE_NOIMPLIED
htmlHandleOmittedElem(1);
#endif
Expand Down
12 changes: 12 additions & 0 deletions test/xml/test_document_fragment.rb
Expand Up @@ -175,6 +175,18 @@ def awesome!
end
assert fragment.children.respond_to?(:awesome!), fragment.children.class
end

def test_for_libxml_in_context_fragment_parsing_bug_workaround
10.times do
begin
fragment = Nokogiri::XML.fragment("<div></div>")
parent = fragment.children.first
child = parent.parse("<h1></h1>").first
parent.add_child child
end
GC.start
end
end
end
end
end

0 comments on commit cedc5d8

Please sign in to comment.