Skip to content

It's possible that 'retrieve a preferred prefix string' returns a wrong prefix for the specified namespace #45

Open

Description

@tkent-google

https://w3c.github.io/DOM-Parsing/#dfn-retrieving-a-preferred-prefix-string
WPT domparsing/XMLSerializer-serializeToString.html has a test case for this behavior."Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix even if the prefix is assigned to another namespace."

const root = (new DOMParser()).parseFromString('<el1 xmlns:p="u1" xmlns:q="u1"><el2 xmlns:q="u2"/></el1>', 'text/xml').documentElement;
root.firstChild.setAttributeNS('u1', 'name', 'v');
console.log((new XMLSerializer()).serializeToString(root));

If we follow the current specification, 'retrieve a preferred prefix string' for name attribute choses q prefix because q is in the list for u1 namespace. However, namespace for q is u2 on the element. The serialization result would be <el1 ...><el2 xmlns:q="u2" q:name="v"/></el1>

Before we add prefix and namespace to a map, we need to remove the prefix associated to another namespace from the map.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions