views:

141

answers:

3
<!-- <script type="text/javascript">/*<![CDATA[*/  c-- ;//]]></script> -->

When I have the above line in the <head> section of a plain html page, Firefox 3.5.5 renders the trailing --> as text. If I change c-- to c- it doesn't. Any ideas what's going on here? I getting an artifact on my pages with this due to a very large script that's been crunched. I can change the statement to c-=1 and avoid the problem for now but.... I'd like to know what bit/byte is biting my a$$.

A: 

I can't replicate this. Doesn't show up on 3.0.1.

dhorn
thanks for checking. very consistent in 3.5.5.
No Refunds No Returns
This does happen Firefox 3.0.5, but only if there is a DOCTYPE present.
Phil Ross
+5  A: 

This is due to Firefox implementing SGML (on which HTML was based) comments strictly. This will only occur when the document is loaded in standards mode (i.e. there is a DOCTYPE).

The first <! starts a comment. The first -- enters a section in which > characters are allowed. The second -- (in your script) leaves the section in which > characters are allowed. The > at the end of </script> then ends the comment. The following --> is therefore no longer part of the the comment and gets rendered as text.

See http://www.howtocreate.co.uk/SGMLComments.html for a fairly comprehensive guide to the issue.

Its also worth noting that the HTML 4 Specification says that 'authors should avoid putting two or more adjacent hyphens inside comments' and the HTML 5 Specification says comments must not 'contain two consecutive U+002D HYPHEN-MINUS characters (--)'.

The solution, as you've found, is to not include -- in the middle of a comment.

Phil Ross
It's probably not quite strictly SGML as it is implemented in Firefox, but even HTML5 disallows two consective hyphens in a comment: http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#comments
mercator
+1  A: 

Technically you are not allowed to have double hyphen in a comment in HTML (or XML). So even if browsers "allow" if it is not valid and should fail an HTML validator.

See Comment section of HTML 4 Specification

James Keesey