See https://github.com/whatwg/html/issues/4016 Simple test case data:text/html,<svg><!|CDATA[ ><p>FAIL
The test case has a typo. CDATA sections are supported, but not in HTML integration points when the current node is still an SVG or MathML element. For example: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/6207 <!DOCTYPE html> <svg><title><![CDATA[x]]></title></svg>
I am able to reproduce based on test case from Comment 01, where in the DOM View, I get following across browsers: *** Safari 15.6 on macOS 12.5 *** #comment: [CDATA[x]] *** Chrome Canary 106 *** #comment: [CDATA[x]] *** Firefox Nightly 105 *** #text: x _____ Just wanted to update the results. Thanks!
<rdar://problem/98460240>
I looked into fixing this and as a start I commented on https://github.com/whatwg/html/issues/4015. Here's the patch I have, but I would like the standards discussion to conclude: diff --git a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp index c138725bb0f0..f63339ac6a35 100644 --- a/Source/WebCore/html/parser/HTMLTreeBuilder.cpp +++ b/Source/WebCore/html/parser/HTMLTreeBuilder.cpp @@ -337,13 +337,13 @@ void HTMLTreeBuilder::constructTree(AtomHTMLToken&& token) else processToken(WTFMove(token)); - bool inForeignContent = !m_tree.isEmpty() - && !isInHTMLNamespace(adjustedCurrentStackItem()) + auto inForeignNamespace = !m_tree.isEmpty() && !isInHTMLNamespace(adjustedCurrentStackItem()); + m_parser.tokenizer().setShouldAllowCDATA(inForeignNamespace); + + auto inForeignContent = inForeignNamespace && !HTMLElementStack::isHTMLIntegrationPoint(m_tree.currentStackItem()) && !HTMLElementStack::isMathMLTextIntegrationPoint(m_tree.currentStackItem()); - m_parser.tokenizer().setForceNullCharacterReplacement(m_insertionMode == InsertionMode::Text || inForeignContent); - m_parser.tokenizer().setShouldAllowCDATA(inForeignContent); #if ASSERT_ENABLED m_destructionProhibited = false;