-
-
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
replace SEGFAULT #759
Comments
Thanks for the report with a simple script! I can reproduce this issue with a slight modification:
I'm still looking into the root cause before committing, but the issue appears to be in ext/nokogiri/xml_node.c:87 where:
Needs to be replaced with
|
Looking at libxml2, tree.c:3850 (xmlReplaceNode)
So, if you replace a node that has no parent, this function does nothing and will return NULL. Nokogiri currently doesn't anticipate this. |
grr, github ate my sample script cause if have not escaped the tags :-). Your simple script in fact is something different: replacing a node that is not connected to the tree indeed should just not happen. My example is different: require 'rubygems' doc = Nokogiri.XML(' ')node = doc.root.add_child(Nokogiri::XML::Node.new('hallo',doc)) nnode1 = Nokogiri::XML::Node.new('hallo',doc) node.replace(nnode1) I think the least suprising behaviour would be that this is working. Meaning: the object node should afterwards be nnode1. |
When you call node.replace(foo), node does not become foo. node gets disconnected from the document. That is the current behavior. Not sure if it's worth changing the API, but the segfault is definitely a bug. An API change would probably best fit into a separate ticket. |
The libxml2 function xmlReplaceNode will return NULL when the node to be replaced has no parent. Nokogiri now anticipates this and returns an exception instead of segfaulting. This fixes issue #759, which includes a good script to reproduce and which was reported by etm.
Fixed with 5a09ab9. |
Can you paste the output of 'nokogiri -v' Aaron Patterson On Sep 13, 2012, at 4:14 AM, eTM [email protected] wrote:
|
Nokogiri (1.5.5)
|
This one somewhat unexpectedly segfaults:
require 'rubygems'
require 'nokogiri'
doc = Nokogiri.XML('
')node = doc.root.add_child(Nokogiri::XML::Node.new('hallo',doc))
nnode1 = Nokogiri::XML::Node.new('hallo',doc)
nnode2 = Nokogiri::XML::Node.new('test',doc)
node.replace(nnode1)
node.replace(nnode2)
This one works:
require 'rubygems'
require 'nokogiri'
doc = Nokogiri.XML('
')node = doc.root.add_child(Nokogiri::XML::Node.new('hallo',doc))
nnode1 = Nokogiri::XML::Node.new('hallo',doc)
nnode2 = Nokogiri::XML::Node.new('test',doc)
node.replace(nnode1)
nnode1.replace(nnode2)
the name "replace" made me expect, that node is now REPLACED by nnode1 and can be used like nnode1. And of course segfaults are never good :-)
Cheers,
eTM
The text was updated successfully, but these errors were encountered: