[whatwg/dom] ProcessingInstruction attribute values containing \r don't roundtrip (Issue #1526)

foolip created an issue (whatwg/dom#1526)

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

https://dom.spec.whatwg.org/#update-data-from-attributes escapes `&`, `<`, `>`, and `"`, but not CR, LF or Tab.

In Chromium we accidentally shipped the same escaping rules as for regular attributes, which differ between HTML and XML, here:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/dom/processing_instruction.cc;l=298;drc=8e3fd1e949738333909fc54a372f8b328ef41be6

HTML test case:

```html
<!DOCTYPE html>
<div><?target?></div>
<script>
div = document.querySelector('div');
pi = div.firstChild;
pi.setAttribute('x', '\r\n\t\xa0');
html = div.outerHTML;
console.log(html);
</script>
```

Chrome will log `<div><?target x="
 &nbsp;"?></div>` (\r\n not escaped, but whitespace is collapsed in this GitHub Markdown comment)

XML test case:

```html
<!DOCTYPE html>
<script>
parser = new DOMParser();
doc = parser.parseFromString('<root><?target?></root>', 'application/xml');
pi = doc.documentElement.firstChild;
pi.setAttribute('x', '\r\n\t\xa0');
serializer = new XMLSerializer();
xml = serializer.serializeToString(doc);
console.log(xml);
</script>
```

Chrome will log `<root><?target x="&#13;&#10;&#9; "?></root>`.

This means that even after https://github.com/whatwg/dom/pull/1524, a literal \r won't roundtrip if serialized and parsed as XML again.

Even if we change the escaping in https://dom.spec.whatwg.org/#update-data-from-attributes escapes it will be possible to set `pi.data` directly and have this issue, so because of that I don't think it's worth changing.

Filing this issue anyway for consideration, as Chromium needs to change.

cc @annevk @hjanuschka @noamr 

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

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

Received on Thursday, 12 November 2026 11:43:57 UTC