-
-
Notifications
You must be signed in to change notification settings - Fork 904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault when creating a comment node for a DocumentFragment #677
Comments
Thanks for the sample code. I can reproduce this on my machine. Looks like we are not handling children of document fragment nodes very well in Nokogiri. In ext/nokogiri/xml_node.c:1387: if (node_has_a_document) {
document = DOC_RUBY_OBJECT(node->doc);
node_cache = DOC_NODE_CACHE(node->doc);
rb_ary_push(node_cache, rb_node);
rb_funcall(document, decorate, 1, rb_node);
} However, the Looks like we need to test if I'll keep this issue updated with progress. |
Ouch. The NOKOGIRI_ROOT_NODE macro gets called in about 20 different places in Nokogiri and it assumes that the doc pointer for a node is an XML document. This breaks when the doc pointer is a document fragment node: in ext/nokogiri/nokogiri.h:123 #define NOKOGIRI_ROOT_NODE(_node) \
st_insert(((nokogiriTuplePtr)(_node)->doc->_private)->unlinkedNodes, (st_data_t)(_node), (st_data_t)(_node)) Nokogiri treats document fragment nodes more like an element than a document (while libxml2 treats it as something in between). I'm still wrapping my head around this. Will continue to update this ticket. |
Thanks for looking into this. I wasn't sure from the documentation whether DocumentFragment was intended to act more like a Document or a NodeSet. |
Pull request merged! |
The following code segfaults under Ruby 1.8.7 and Nokogiri 1.5.2
Error message:
The text was updated successfully, but these errors were encountered: