Add integration point CDATA tests

Merged
SI
3mo ago
+61-0

Add tree construction tests for apparent CDATA sections in different contexts.

Browsers currently have different behaviors and this has confused implementors in the past, see https://github.com/whatwg/html/issues/8558 and WordPress' HTML parser I work on.

See https://github.com/whatwg/html/issues/4016 and https://github.com/whatwg/html/issues/4016#issuecomment-4913918477:

Here's an example:

<svg>␀(null becomes U+FFFD in foreign content)
  <title><![CDATA[this should be text]]></title>
  <desc><![CDATA[this should be text]]></desc>
  <foreignObject><![CDATA[this should be text]]></foreignObject>
</svg>
<math>
  <annotation-xml encoding="text/html"><![CDATA[this should be text]]></annotation-xml>
  <mtext>␀(null character token is ignored in HTML insertion modes)<![CDATA[this should be text]]></mtext>
</math>

(The above example includes some null bytes, shown as ␀ for clarity.)

All tested browsers handle character tokens correctly: U+0000 NULL is ignored at integration points and becomes U+FFFD (�) in foreign content. The issue is limited to CDATA section tokenization.

In my testing of Chrome 150, Safari 26.5, Edge 150, and Firefox 152, only Firefox adheres to the spec.

Chrome, Safari, EdgeFirefox
└─HTML
  ├─HEAD
  └─BODY
    ├─svg:svg
    │ ├─#text �(null becomes U+FFFD in foreign content)
    │ ├─svg:title
    │ │ └─#comment [CDATA[this should be text]]
    │ ├─svg:desc
    │ │ └─#comment [CDATA[this should be text]]
    │ └─svg:foreignObject
    │   └─#comment [CDATA[this should be text]]
    └─math:math
      ├─math:annotation-xml encoding="text/html"
      │ └─#comment [CDATA[this should be text]]
      └─math:mtext
        ├─#text (null character token is ignored in HTML insertion modes)
        └─#comment [CDATA[this should be text]]
└─HTML
  ├─HEAD
  └─BODY
    ├─svg:svg
    │ ├─#text �(null becomes U+FFFD in foreign content)
    │ ├─svg:title
    │ │ └─#text this should be text
    │ ├─svg:desc
    │ │ └─#text this should be text
    │ └─svg:foreignObject
    │   └─#text this should be text
    └─math:math
      ├─math:annotation-xml encoding="text/html"
      │ └─#text this should be text
      └─math:mtext
        └─#text (null character token is ignored in HTML insertion modes)this should be text