-
-
Notifications
You must be signed in to change notification settings - Fork 905
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
Replacing a Node from another document will crash on exit #162
Comments
I believe what ration meant to say was:
|
Node#replace reimplemented using reparent_node_with. Fixed by ebd4483 |
Ah yes, I didn't notice that the markdown broke the tags.. With this fix, doc2 will not contain the caption element. Is this the preferred behavior? |
yes, this is the preferred behavior. if you want to copy the node, copy it: |
Ok, thanks for the fix! Moving was actually what I wanted, so this is perfect. I might not be the only one who doesn't automatically see this behavior, so maybe the documentation for replace deserves a comment about this side effect for the originating doc. |
If you replace a node from another document, there is a crash on exit. A Node is probably referenced from both documents and tried to delete twice.
Example:
!/usr/bin/env ruby
require 'nokogiri'
xml1 = "
Original caption " xml2 = " Replacement caption " doc1 = Nokogiri::XML(xml1) doc2 = Nokogiri::XML(xml2) caption1 = doc1.xpath("//caption")[0] caption2 = doc2.xpath("//caption")[0] caption1.replace(caption2)The text was updated successfully, but these errors were encountered: