Bug 17722 - HTML5 spec violation: </><!doctype html> or </x><!doctype html> SHOULD NOT imply standards mode
Summary: HTML5 spec violation: </><!doctype html> or </x><!doctype html> SHOULD NOT im...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Adam Barth
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-03-08 03:29 PST by Robert Blaut
Modified: 2010-09-16 02:05 PDT (History)
4 users (show)

See Also:


Attachments
Patch (2.64 KB, patch)
2010-09-13 17:38 PDT, Adam Barth
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Blaut 2008-03-08 03:29:39 PST
The code: </><!doctype html> or </x><!doctype html> makes Webkit to render page in standards mode (CSS1Compat). 

According to HTML5 spec: 
"Documents must consist of the following parts, in the given order:
1. Optionally, a single U+FEFF BYTE ORDER MARK (BOM) character.
2. Any number of comments and space characters.
3. A DOCTYPE." 

Only BOM, comments and space characters are allowed before DOCTYPE.

Steps to reproduce:
1) Go to a page: http://software.hixie.ch/utilities/js/live-dom-viewer/?%20%3C%2F%3E%3C!doctype%20html%3E%0A and notice "CSS1Compat" in log section.

Expected result:
BackCompat in log section

Current result:
CSS1Compat in log section
Comment 1 Adam Barth 2010-08-05 10:17:43 PDT
The spec mandates that we render this document standards mode.  Our current behavior is correct.
Comment 2 Anne van Kesteren 2010-08-05 23:24:12 PDT
As far as I can tell anything but whitespace, comments, and DOCTYPEs throws you out of the "initial" insertion mode and puts the document in standards mode so if this bug still applies with the new parser there is a bug. (And a lack of tests :/)
Comment 3 Anne van Kesteren 2010-08-05 23:24:53 PDT
I meant to say puts the document in quirks mode. Argh.
Comment 4 Adam Barth 2010-08-05 23:33:24 PDT
Ok.  I'll take another look.
Comment 5 Adam Barth 2010-09-13 16:59:09 PDT
Looking now.
Comment 6 Adam Barth 2010-09-13 17:32:16 PDT
Looks like our behavior is correct.  Adding tests.
Comment 7 Adam Barth 2010-09-13 17:38:03 PDT
Created attachment 67494 [details]
Patch
Comment 8 Eric Seidel (no email) 2010-09-13 18:08:12 PDT
Comment on attachment 67494 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=67494&action=prettypatch

Better to have it say PASS or FAIL, but this is OK.
Comment 9 Adam Barth 2010-09-14 11:45:28 PDT
PASS/FAIL tests are hard to change latter if we're intentionally changing behavior.
Comment 10 WebKit Commit Bot 2010-09-14 12:24:15 PDT
Comment on attachment 67494 [details]
Patch

Clearing flags on attachment: 67494

Committed r67484: <http://trac.webkit.org/changeset/67484>
Comment 11 WebKit Commit Bot 2010-09-14 12:24:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Robert Blaut 2010-09-14 22:36:15 PDT
(In reply to comment #6)
> Looks like our behavior is correct.  Adding tests.

Adam, could you explain why the current behavior is correct?
Comment 13 Adam Barth 2010-09-15 00:32:54 PDT
> Adam, could you explain why the current behavior is correct?

Sure.

</x><!doctype html>

This case generates a close tag token for the </x>, which kicks us out of the initial model, so the doctype doesn't trigger standards mode.  Hence, quirks.

</><!doctype html> or 

This case doesn't generate any token for </>.  It just gets eaten by the tokenizer.  That means the first token we see is the doctype, which triggers standards mode.  Hence, standards.
Comment 14 Robert Blaut 2010-09-16 01:41:36 PDT
(In reply to comment #13)

> </><!doctype html> or 
> 
> This case doesn't generate any token for </>.  It just gets eaten by the tokenizer.  That means the first token we see is the doctype, which triggers standards mode.  Hence, standards.

Is it correct behavior according HTML5 specification [http://www.w3.org/TR/html5/syntax.html#writing]?
Comment 15 Adam Barth 2010-09-16 02:05:27 PDT
> Is it correct behavior according HTML5 specification [http://www.w3.org/TR/html5/syntax.html#writing]?

Yes.  Notice the first sentence of that section:

[[
This section only applies to documents, authoring tools, and markup generators. In particular, it does not apply to conformance checkers; conformance checkers must use the requirements given in the next section ("parsing HTML documents").
]]