Skip to content
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] CRuby node reparenting namespace issue #3459

Open
flavorjones opened this issue Mar 9, 2025 · 1 comment · May be fixed by #3462
Open

[bug] CRuby node reparenting namespace issue #3459

flavorjones opened this issue Mar 9, 2025 · 1 comment · May be fixed by #3462

Comments

@flavorjones
Copy link
Member

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.

@flavorjones
Copy link
Member Author

I've got a simple fix for this, will finish it up tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant