Skip to content

[bug] CRuby node reparenting namespace issue #3459

@flavorjones

Description

@flavorjones

Please describe the bug

  it "foo" do
    doc = Nokogiri::XML(<<~XML)
      <dnd:adventure xmlns:dnd="http://www.w3.org/dungeons#">
        <dnd:party xmlns:dnd="http://www.w3.org/dragons#">
          <dnd:members>
          </dnd:members>
        </dnd:party>
      </dnd:adventure>      
    XML

    dungeons_ns = doc.root.namespace_definitions.find { |ns| ns.prefix == "dnd" }
    parent = doc.xpath("//ns:members", ns: "http://www.w3.org/dragons#").first

    node = doc.create_element("character")
    node.namespace = dungeons_ns
    parent.add_child(node)

    # passes, indicating it's not a reparenting issues
    assert_equal("http://www.w3.org/dungeons#", node.namespace.href)
    # fails, maybe this is a serialization issue? not sure.
    assert_includes(doc.to_xml, %Q{<dnd:character xmlns:dnd="http://www.w3.org/dungeons#"/>})
  end

Additional context

I'm pretty sure this is a bug in relink_namespaces which I've wanted to replace for quite a while, see #2919 for other options.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions