Bug 189431 - CDATA section are not supported in SVG/MathML in HTML
Summary: CDATA section are not supported in SVG/MathML in HTML
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-09-07 14:03 PDT by Simon Pieters (:zcorpan)
Modified: 2024-01-30 03:01 PST (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Pieters (:zcorpan) 2018-09-07 14:03:02 PDT
See https://github.com/whatwg/html/issues/4016

Simple test case

data:text/html,<svg><!|CDATA[ ><p>FAIL
Comment 1 Simon Pieters (:zcorpan) 2018-09-07 14:13:24 PDT
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>
Comment 2 Ahmad Saleem 2022-08-09 13:46:51 PDT
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!
Comment 3 Radar WebKit Bug Importer 2022-08-10 10:59:03 PDT
<rdar://problem/98460240>
Comment 4 Anne van Kesteren 2023-12-18 08:40:55 PST
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;