W3C home > Mailing lists > Public > www-validator@w3.org > May 2008

Re: HTML Comment In Script Elements

From: Jukka K. Korpela <jkorpela@cs.tut.fi>
Date: Mon, 12 May 2008 08:51:05 +0300
Message-ID: <003801c8b3f4$2bfd93d0$0500000a@DOCENDO>
To: "Kravvitz" <Kravvitz.css-validator@dynamicsitesolutions.com>, <www-validator@w3.org>

Kravvitz wrote:

> Is it intentional that the HTML Validator doesn't give an error
> message when an HTML comment is started in a <script> element but the
> end of it is missing in an HTML document?

There are no HTML comments inside a <script> element, since the content 
model is CDATA, which means that no markup is recognized, except for end 
tags. Thus, from the viewpoint of HTML syntax, "<!--" inside a <script> 
element is just character data.

> It does show error messages
> as a result of this error in XHTML documents.

In XHTML, the content model is #PCDATA, which means that markup is 
recognized.

In practice, "<!--" inside a <script> element is risky in XHTML 
documents, since when the document is processed genuinely as XHTML, the 
browser or other processor _may_ remove comments before any other 
processing, but is not required to. And when processed as classic HTML, 
which is the only way to make XHTML digestible to IE, such "comments" 
are not removed but passed to the script language processor.

Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/ 
Received on Monday, 12 May 2008 05:51:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:29 GMT