Skip to content
Browse files
iframe srcdoc with quirky doctype should be no-quirks mode

Reviewed by Chris Dumez.

This patch addresses the bug that a document in srcdoc can be in quirks mode due to DOCTYPE.
New behavior of WebKit matches the spec, Gecko, and Blink.

* LayoutTests/fast/parser/strict-mode-in-srcdoc-with-quirks-doctype-expected.txt: Added.
* LayoutTests/fast/parser/strict-mode-in-srcdoc-with-quirks-doctype.html: Added.
* LayoutTests/fast/frames/srcdoc/srcdoc-can-be-in-qurks-mode-expected.txt:

* Source/WebCore/html/parser/HTMLConstructionSite.cpp:

Canonical link:
  • Loading branch information
rniwa committed Aug 11, 2022
1 parent 593162b commit 4401d4e5b5d9e430acd08167d20557dfcc20a569
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
@@ -1,2 +1,2 @@
ALERT: BackCompat
Normally srcdoc documents default to standards mode, but they can end up in quirks mode with a sufficiently nutty DocType.
@@ -0,0 +1,13 @@
This tests that the documents in srcdoc are always in strict mode

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".

PASS frame1.contentDocument.compatMode is "CSS1Compat"
PASS frame2.contentDocument.compatMode is "CSS1Compat"
PASS frame3.contentDocument.compatMode is "CSS1Compat"
PASS frame4.contentDocument.compatMode is "CSS1Compat"
PASS successfullyParsed is true


@@ -0,0 +1,22 @@
<!DOCTYPE html>
<script src='../../resources/js-test.js'></script>
<iframe id="frame1" srcdoc='<!doctype x>'></iframe>
<iframe id="frame2" srcdoc='<!doctype html public "-//w3c//dtd html 3.2//en">'></iframe>
<iframe id="frame3" srcdoc='<!doctype "-//w3c//dtd html 3.2//en">'></iframe>
<iframe id="frame4" srcdoc='<!doctype html -//w3c//dtd xhtml 1.0 frameset//">'></iframe>

description('This tests that the documents in srcdoc are always in strict mode');

onload = () => {
shouldBeEqualToString('frame1.contentDocument.compatMode', 'CSS1Compat');
shouldBeEqualToString('frame2.contentDocument.compatMode', 'CSS1Compat');
shouldBeEqualToString('frame3.contentDocument.compatMode', 'CSS1Compat');
shouldBeEqualToString('frame4.contentDocument.compatMode', 'CSS1Compat');

@@ -342,6 +342,11 @@ void HTMLConstructionSite::setCompatibilityModeFromDoctype(const String& name, c
// Limited Quirks - This mode is identical to no-quirks mode except for its treatment of line-height in the inline box model.
// No Quirks - no quirks apply. Web pages will obey the specifications to the letter.

if (m_document.isSrcdocDocument()) {

// Check for Quirks Mode.
if (name != "html"_s
|| startsWithLettersIgnoringASCIICase(publicId, "+//silmaril//dtd html pro v0r11 19970101//"_s)
@@ -445,7 +450,7 @@ void HTMLConstructionSite::insertDoctype(AtomHTMLToken&& token)
if (m_isParsingFragment)

if (token.forceQuirks())
if (token.forceQuirks() && !m_document.isSrcdocDocument())
setCompatibilityModeFromDoctype(, publicId, systemId);

0 comments on commit 4401d4e

Please sign in to comment.