[whatwg/dom] Processing instruction attribute names that setAttribute() accepts don't survive reparsing (Issue #1523)

annevk created an issue (whatwg/dom#1523)

### What is the issue with the DOM Standard?

`setAttribute()` and `toggleAttribute()` on `ProcessingInstruction` accept any [valid attribute local name](https://dom.spec.whatwg.org/#valid-attribute-local-name). But [update attributes from data](https://dom.spec.whatwg.org/#update-attributes-from-data) uses the xml-stylesheet [rules for parsing pseudo-attributes](https://www.w3.org/TR/xml-stylesheet/#dt-parsing), which require each name to match XML's `Name` production. As a result, `setAttribute()` can write data that no longer parses back into the same attributes:

```js
const pi = document.createProcessingInstruction("t", "");
pi.setAttribute("$", "x");
pi.getAttribute("$"); // "x"
pi.data = pi.data;
pi.getAttribute("$"); // null, and the whole map is now empty
```

`$` isn't an XML NameStartChar, but [processing-instruction-attributes.html](https://github.com/web-platform-tests/wpt/blob/master/dom/nodes/processing-instruction-attributes.html) requires `setAttribute("$", …)` to work. Names containing `"`, `'`, `<`, or `&` are allowed too, and they produce data that isn't well formed: `pi.setAttribute('a"b', "x")` gives `a"b="x"`.

Clones and range copies run into the same problem if they reparse their data (see #1504).

cc @foolip @noamr


-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1523
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1523@github.com>

Received on Tuesday, 10 November 2026 07:27:18 UTC