[thelist] Mozilla and multiple dashes

Andrew Clover and-evolt at doxdesk.com
Thu Aug 5 05:40:25 CDT 2004


<John.Brooking at sappi.com> wrote:

> Seems to be something about causing the browser to parse the comments
> and the code around it improperly. Anyone else ever encountered this?

It's not improper, it's correct. According to SGML, on which the 
original HTML was based, multiple comments can be interleaved with 
declarations:

   <!-- comment 1 -- NOT A COMMENT -- another comment -->

Since there is no declaration HTML users can usefully put in the bit 
marked NOT A COMMENT this is purely vestigial, but from a parsing 
point-of-view it means that this:

   <!-- comment -- NOT A COMMENT -->

is an unclosed comment - the final '>' character is part of a comment 
instead of closing it.

XML avoids this confusion by saying that comments end with '-->' and any 
other use of '--' in comments is explicitly forbidden, but unless you're 
testing XHTML served with an XML filetype this error won't generally be 
flagged.

> Doesn't anyone else use lines of dashes in comments?

Lots of people, but they're all wrong.

Sometimes they will get away with it by using a number of dashes that 
leaves the parser in comment mode before closing with the final '-->'; 
some rely on the browser's error-recovery features and hence break on 
some browsers as you have experienced. Different browsers have 
different, intricate strategies for recovering from broken comments.

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/


More information about the thelist mailing list