-
-
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
[bug] When copying between documents nokogiri strips attribute namespace if it differs from tag's #2228
Comments
@fiddlededee Hi, thanks for opening this isue, and I'm sorry you're having problems. I unfortunately can't reproduce what you're seeing -- the above test passes on my system, and unfortunately since you didn't answer the questions in the issue template. Here's my setup:
Can you please post the output from |
Um, ok, I'm multitasking and didn't catch that this isn't a failing test. Can you please rewrite this to be a failing test that describes the behavior you think should be exhibited? |
No problem. Nokogiri is great in all respects. The previous code just tested that my workaround works. Still this workaround looks escessive. The following test in my opinion should pass, but it fails. class TestAttributeNsCopied
describe "Nokogiri" do
before do
@xml_text_src = <<-TESTXML
<p1:a xmlns:p1="ns1" xmlns:p2="ns2">
<p1:b p2:c="d">
</p1:a>
TESTXML
@xml_text_dest = <<-TESTXML
<p1:a xmlns:p1="ns1" xmlns:p2="ns2">
</p1:a>
TESTXML
@xml_doc_src = Nokogiri::XML @xml_text_src
@xml_doc_dest = Nokogiri::XML @xml_text_dest
end
it "should not lose attribute namespace" do
ns = {'p1': "ns1", 'p2': "ns2"}
node_dest = @xml_doc_dest.xpath("//p1:a", ns)[0]
node_to_insert = @xml_doc_src.xpath("//p1:b", ns)[0]
node_dest.add_child node_to_insert
assert_equal @xml_doc_dest.xpath("/p1:a/p1:b",
ns)[0].attribute_with_ns('c', 'ns2').to_s,
"d", "check namespace remained"
end
end
end My setup is
|
@fiddlededee Thank you for the failing test -- I agree that the current behavior feels wrong. I'm going to dig into what's happening and why. |
@fiddlededee I believe you've found a bug in libxml2. I'm going to file a bug report upstream and suggest a fix; and I will consider including the patch in the next version of Nokogiri. Stay tuned. |
Previously, the namespace was dropped from the attribute. Fixes #2228 Co-authored-by: Nikolaj Potashnikoff <34554890+fiddlededee@users.noreply.github.com>
Previously, the namespace was dropped from the attribute. Fixes #2228 Co-authored-by: Nikolaj Potashnikoff <34554890+fiddlededee@users.noreply.github.com>
Update: this was indeed a bug in how Nokogiri was duplicating nodes to be copied to another document. See #2230 for the PR. |
When copying between documents nokogiri strips attribute namespace if it differs from tag's
Here is the test that checks current (in my opionion erroneous behaviour).
assert_nil
should fail but it passes.The text was updated successfully, but these errors were encountered: