Skip to content

Commit

Permalink
Add test for namespace reparenting issue sparklemotion#2494.
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyE committed Apr 3, 2022
1 parent fb83666 commit 0395906
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/xml/test_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<root xmlns="#{root_namespace_href}">
<child1 xmlns="#{child1_namespace_href}"/>
<child2/>
</root>
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

0 comments on commit 0395906

Please sign in to comment.