From 039590604d0b6b6a4d6b1b1a6e8ce07b9c13ca88 Mon Sep 17 00:00:00 2001 From: Trey Evans Date: Sun, 3 Apr 2022 10:59:23 -0400 Subject: [PATCH] Add test for namespace reparenting issue #2494. --- test/xml/test_namespace.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/xml/test_namespace.rb b/test/xml/test_namespace.rb index 74ee6d100a5..4f3d5ae5937 100644 --- a/test/xml/test_namespace.rb +++ b/test/xml/test_namespace.rb @@ -93,6 +93,28 @@ def test_maintain_element_namespaces_in_urn assert_equal("urn:xmpp:foospec:barfoo", child.namespace.href) assert_empty(child.attributes) end + + def test_maintain_element_namespaces_with_abbreviation_squating + root_namespace_href = "urn:root_namespace" + child1_namespace_href = "urn:child1_namespace" + doc = Nokogiri::XML(<<-eoxml) + + + + + eoxml + + child2 = doc.at_xpath("//ns1:child2", { "ns1" => root_namespace_href }) + child1 = doc.at_xpath("//ns2:child1", { "ns2" => child1_namespace_href }) + child1.add_child(child2) + new_xml = doc.to_xml + + new_doc = Nokogiri::XML(new_xml) + new_child1 = new_doc.at_xpath("//ns2:child1", { "ns2" => child1_namespace_href }) + new_child2 = new_child1.first_element_child + new_child2_ns_href = new_child2.namespace.href + assert_equal(root_namespace_href, new_child2_ns_href) + end end end end