-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
[bug] Reparenting of nodes can get wrong namespaces when prefixes are reused #2494
Comments
Thank you for opening this as well as submitting a PR for it! I want to spend some time understanding the bug report and re-building context around the reparenting code, which has always been complex and tricky to get right. Please give me a day or two! Thanks. |
@flavorjones NP! Thanks for getting back to me. This is my first major C submission here and understand I might not have gotten everything exactly right - so take as much time as you need. |
For whatever it's worth, I think the behavior we should be striving for is described in #1200 (comment) And I think we probably need to make whatever fix we adopt be in v2.0 and call it a breaking change (which it will be for some use cases). |
If I reuse namespace prefixes for different nodes (such as when I use a blank XML namespace, i.e. xmlns=), I can get the wrong namespace when the node is reparented.
Code that Causes the Error
Note that this will now output incorrect namespaces on the "child2" node, like the following:
Note that the "child2" node has now been incorrectly 'moved' into the "urn:something_else" namespace.
A more correct output would be something similar to:
Source of the Behaviour
I've tracked this down to
static void relink_namespace(xmlNodePtr reparented)
inext/nokogiri/xml_node.c
.It seems this code doesn't check for nodes above the current node possibly 'squatting' on a namespace, for example:
Tests and PRs
A test which reproduces this issue an an associated correction are provided in PR #2495.
The text was updated successfully, but these errors were encountered: