C.H.U.B. - Comment Hyphenation Ugh Bug
I recently encountered a bug on one of my sites that has to be the weirdest thing I’ve ever seen. It was a major rendering issue on a single page — the main Showcase page at Accessites.org.
This bug was discovered and reported by Virginia DeBolt, a Macintosh computer OS 10.4 user running the version 2.0 Safari browser. The bug would only manifest itself on that system. Special attention was given to Accessites to ensure it was extremely accessible and cross-browser compatible, so this came as a shock. The result, however was an undeniably unreadable and horrible-looking page.
As you can see in the image floated to the right, The Mac OS10.4 Safari 2.0 render (the background of the image) was all blue, the page background image was peering through the content, and said content was messed up. You can see what it’s supposed to look like in the inset thumbnail. Also shown in this image, the zoomed-in part, you can see the tail of a comment: -->
. This was the big clue.
Since this was the only page affected, and the only theme affected didn’t help solve the matter. The markup was the same for all themes, and the site’s Home page had the same content plug-in, the RSS Newsmaker part of the GreenBeast CMS. Very strange. Still that comment tail was visible. Could it be something on that page that made it react to the page’s commenting this way?
I conferred with my friend and master CSS guru, Thierry Koblentz. He couldn’t really point out anything that was the sure-cause of the issue, but he did suggest removing nested hypens within two comments on the page. I was game to try anything. Adding a hyphen within a comment is fine, normally, as long as two consecutive hyphens aren’t used all is hunky-dory. Example:
<!-- adding a single hyphen - like this -->
is fine.
<!-- adding a two consecutive hyphens -- like this -->
is not.
In this circumstance I had two comments on the page with single hyphen nested within them. I removed them upon Thierry’s suggestion. Amazingly this fixed the problem. The whys and what-fors are still a mystery. The best I can tell, the comment was stopped after the first hyphen in comment one, in the head, then resumed after the second single hyphen in comment two, further down the page (right where the page began display in the screenshot). Why this was happening seems to be a browser bug (and something to do with that page and that page only), but is almost guaranteed to run even deeper than that. It’s fixed now but it doesn’t make sense. The markup, including those hyphenated comments, was the same as the Home page, yet the home page was fine. If you have an issue like this with a page, and you have single hyphens within comments like I did, remove them, test it, and let me know if this fix works for you.
Special thanks goes to Marco Battilana for suggesting I give it a name (new bug fame). The “Ugh” part of it is there for two reasons: To make it speakable, and that demonstrates the frustration part of this little issue.
Neal Venditto responds:
Posted: March 22nd, 2006 at 8:28 pm →
Yes, when commenting you need to be careful. I generally just avoid commenting HTML althogether, but never use hyphens for the reason you mentioned above. Even single hyphens in some older browsers caused issues (Suprised that Safari 2.0 chokes on this, though). But from working with different programming and scripting languages, I’m loathe to use anything but alphanumeric characters, spaces, periods, and commas in comments. If you need fuller puctuation then it probably belongs in a readme or documentation.
Marco Battilana responds:
Posted: March 23rd, 2006 at 1:06 am →
Hey, thanks for the plug!
I guess C.H.U.B. is better than calling it ‘Mike’s Hyphen in the Comment’ bug. M.H.I.T.C.B. just doesn’t have the same ring to it
Mike Cherim responds:
Posted: March 23rd, 2006 at 1:26 am →
@Neal: Yeah, I’m going avoid C.H.U.Bs like the plague.
@Marco: That is sort of what I started with then decided otherwise.
Thomas Tallyce responds:
Posted: March 24th, 2006 at 9:08 pm →
I think you might find that -- is actually technically the close of a comment, so this is not a bug. I’m not certain; search out the relevant HTML documentation to be sure.
http://www.htmlhelp.com/reference/wilbur/misc/comment.html
“A comment starts and ends with “--”, and does not contain any occurrence of “--”.”
The official spec says:
http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.4
“the comment close delimiter (“--”)”
“A common error is to include a string of hyphens (“---”) within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.”
Mike Cherim responds:
Posted: March 24th, 2006 at 9:35 pm →
Thanks Thomas. It is true, but the weird thing in this case was I only had a single hyphen in the comment and the opening and closing was done properly. What’s even stranger was (due to globally included files) it was done exactly the same way on every page, yet that was the only page it showed up on according to Virginia, even that page’s appending pages were okay. Yet, removing the two hyphens, one in one comment and one in another, but both on the same page, seemed to fix it. It has got to be the most nonsensical things I ever seen.
James Cram responds:
Posted: March 25th, 2006 at 2:23 pm →
Strange indeed… I believe Safari’s handling of hyphens in comments was changed in order for it to pass the Acid 2 Test so I guess this bug got introduced then.
Robert Wellock responds:
Posted: April 21st, 2006 at 5:29 am →
I know I am late to this but is not a bug as such other than probably displaying the dashes. I was surprised you managed to make that mistake of using — inside comments quite a lot of beginners do that for odd reasons. http://www.howtocreate.co.uk/SGMLComments.html
Mike Cherim responds:
Posted: April 21st, 2006 at 8:26 am →
I didn’t make that n00b mistake, Robert. This is what I had:
<!-- This is comment one - with a single dash in it -->
And also on the same page I had this:
<!-- This is comment two - also with a single dash in it -->
This isn’t normally a problem, and it wasn’t on other pages with the same exact mark-up (global includes were used). And this isn’t listed on the reference you gave and problem causing.
Robert Wellock responds:
Posted: April 25th, 2006 at 7:21 am →
I must have though you meant nested comments, or consecutive dashes to begin with or one not surrounded by text. As obviously they’d fail well-formedness anyway. Though if they were two separate independent instances containing only one single dash between characters, i.e. then it is a bug assuming other script isn’t triggering it.
Mike Cherim responds:
Posted: April 26th, 2006 at 11:45 pm →
Yeah, it’s pretty bizarre. Content excluded, that page, the Showcase Page, and the Home Page are identical, most of the files in fact are shared, and the same script is being run. It really stumped all of us because it’s one of those things we say that ain’t right to.