w3c / w3c/DOM-Parsing

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

Open
#45 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

xml-serialization
Dominant language
HTML
Stars
28
Forks
14
Avg merge
3h 10m
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the DOM-Parsing specification section on “retrieving a preferred prefix string” and the WPT case in domparsing/XMLSerializer-serializeToString.html. Reproduce the XMLSerializer example, then trace how prefixes are selected and mapped during serialization. Done means the specified namespace case serializes with a prefix bound to the correct namespace and the WPT test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, xml
Domain
testing, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.