Re: [w3c/DOM-Parsing] Serialization algorithm never preserves attribute prefixes (#29)

Adding the condition at https://github.com/jsdom/w3c-xmlserializer/blob/master/lib/attributes.js#L92 is the solution by @sebmaster.  That matches the current state of WPT.

@bwrrp has a slightly better complicated proposal in https://github.com/bwrrp/DOM-Parsing/commit/97e7bb3182f28555d2b5deff01a75d1a87cfd346 which also preserves the prefix name in the case where the attribute has a prefix but it hasn't (yet) been properly declared.  The "'Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used." test at https://github.com/web-platform-tests/wpt/blame/master/domparsing/XMLSerializer-serializeToString.html#L126 would have to be updated if this change were made to the spec.  Firefox appears to already implement this change, though:
```js
> doc = (new DOMParser()).parseFromString("<r xmlns:xx=\"uri\"></r>", "text/xml");
> root = doc.firstChild;
> root.setAttributeNS('uri2', 'p:name', 'value');
> (new XMLSerializer()).serializeToString($doc)
"<r xmlns:xx=\"uri\" p:name=\"value\" xmlns:p=\"uri2\"/>"
```
(The WPT test case states the output should be `<r xmlns:xx="uri" xmlns:ns1="uri2" ns1:name="value"/>` which is what https://github.com/jsdom/w3c-xmlserializer/blob/master/lib/attributes.js would emit.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/DOM-Parsing/issues/29#issuecomment-873176757

Received on Friday, 2 July 2021 18:17:43 UTC