When more forgiving is less forgiving
Strange lessons can be found where you least expect them. In a forum I frequent, I just witnessed someone ask why his site design breaks, but only in Internet Explorer. It turns out that this person had put <!-- some comment here --!>
somewhere in the markup, which obviously didn’t work because there’s an extraneous exclamation mark before the closing angle bracket.
Why did it work in other browsers? Because they actually make an attempt to implement the SGML spec. This spec does not directly define a way to insert comments in a document, but it allows comments delimited by --
to occur within declarations, which in turn are opened with <!
and closed with a simple >
. This is how the familiar <!-- -->
comes about: it’s an empty declaration (<! >
) with a comment (-- a comment --
) inside.
To compliant browsers which implement the spec correctly, the aforementioned <!-- --!>
form looks like a declaration which contains a comment and an extraneous exclamation mark. The latter is syntatically incorrect, but is silently ignored (unless you are in strict compliance mode, in which case Firefox gives you the yellow screen of death).
IE on the other hand does the naïve thing and simply looks for <!--
to open a comment and -->
to close it. As it finds no such thing in the aforementioned string, the page malfunctions.
Something that amuses me particularly about this case is that I can see it construed as an argument both in favour of and in opposition to draconian error handling. Life, it often seems, can be defined as the absence of easy answers…