W3C home > Mailing lists > Public > www-html@w3.org > May 2007

Re: Cleaning House

From: Philip Taylor <philip@zaynar.demon.co.uk>
Date: Thu, 03 May 2007 15:09:09 +0200
To: www-html@w3.org
Message-ID: <4639DEAF.8090702@zaynar.demon.co.uk>

(Apologies if duplicated - an earlier copy fell into a moderation queue,
and this copy has a bug fix anyway.)

Lachlan Hunt wrote:
> David Woolley wrote:
>> [...] HTML4 requires that the document be valid with orwithout the  
>> document.writes executed, but I think the HTML5 rules allowthe script  
>> to generate unbalanced tags.
> No it doesn't.  Why would you assume such a thing?

Since it's not entirely obvious, it might be helpful to show how the
HTML5 rules don't allow that.

My understanding is that a document like

      <script>document.write('<b>Hello world');</script>

is non-conforming because:

* Document conformance is unrelated to whether a certain UA has
scripting enabled (this isn't stated anywhere that I can find, but I
think it's a valid belief), hence it is safe to assume scripting is  

* The input stream tokenises all the tags up to and including the  

* Simultaneously, the parsing algorithm inserts elements into the document.

* Because scripting is enabled, when the script element is inserted, the
script is executed.

* "<b>Hello world" is appended to the input stream at its current
insertion point (just after the </script>).

* The tokenising and parsing algorithms continue with the new input stream.

* The parsing algorithm reaches the end of the document, and the lack of
</b> causes a parse error.

* (I can't actually see an explicit mention that documents must not
cause parse errors - only that conformance checkers should (or, if it
happens when scripting is disabled, must) report a parse error. But I
think it's fairly obvious that such documents are meant to be considered
non-conforming, even if it might need clarification.)

Given the first point (that document conformance is unrelated to whether
scripting is enabled), I believe that also means

      <script>document.write('<b>Hello world');</script>

is non-conforming (even though it would not cause any parse errors in a
UA with scripting enabled).

But I believe scripts can technically still generate unbalanced tags
(within the scope of that script, not the whole document), because


would be conforming regardless of whether scripting is enabled.

Philip Taylor
Received on Monday, 7 May 2007 15:21:29 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:16 UTC