- From: Philip Taylor <philip@zaynar.demon.co.uk>
- Date: Thu, 03 May 2007 14:42:55 +0200
- To: www-html@w3.org
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 <!DOCTYPE HTML> <title></title> <p> <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 enabled. * The input stream tokenises all the tags up to and including the </script>. * 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 <!DOCTYPE HTML> <title></title> <p> <script>document.write('<b>Hello world');</script> </b> 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, because <!DOCTYPE HTML> <title></title> <p> <script>document.write('<b>Hello');</script> <script>document.write('world</b>');</script> would be conforming regardless of whether scripting is enabled. -- Philip Taylor philip@zaynar.demon.co.uk
Received on Monday, 7 May 2007 15:20:59 UTC