views:

220

answers:

2

I think i have identified a bug in the way ASP handles IE conditional comments (or html comments in general)..

In theory it should not handle them at all since they are meant for the client-side..

In practice ..

<!--[if IE 6]>
<!--include virtual="emptyfile.asp"-->
<![endif]-->

will return

<![endif]>

Yes, you read that correctly.. it will remove the opening of the comment include whatever is in the file and keep the closing comment tag..

This of'course will mess up the html and of'course make whatever was for the IE to be executed for all...

there are obvious workaround such as using server.execute to include your file instead of the include directive, which will work as expected..

Most likely it confuses the ending --> of the include directive with the opening <!-- of the html comment.. But it should not bother with html comments at all..

Is there a know reason this happens in this way ? or is it just a bug ?

A: 

If you are testing in IE 8 then the will be ,

please check this link http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

conditional comments for different versions of IE.

Ravia
Actually the problem happens in all browsers.. since it is a server misbehavior and not a client one..
Gaby
It is not a bug as mentioned in above answer, thanks Anthony
Ravia
+3  A: 

This is not a bug.

The asp include syntax expects to find the keyword #include in a markup comment. However it does not require that there only be white space from the end of the comment start sequence until the #include keyword. Hence this is quite legal:-

 <!-- pink elephants #include virtual="myinc.asp" -->

This is also legal:-

 <!--
 #include virtual="myinc.asp"
 -->

Now any subsequent occurence of the <!-- inside a comment is treated just like any other text. Hence this is still legal:-

<!--
<!-- #include virtual="myinc.asp" -->

Its the first <!-- which begins the comment which is seen as an include marker by ASP. The second is just ignored text. The whole comment is replaced by the contents of the "myinc.asp" file. If the file happens to be empty then the comment is simply deleted.

Now the extra [if IE 6]> is still just ignored text so the whole of [if IE 6>\r\n<!-- will be ignored text. Thus:-

<!--[if IE 6>
<!-- #include virtual="emptyfile.asp" -->

Is replaced by the contents of "emptyfile.asp". Any subsequent:-

<![endif]-->

Is sent verbatim.

AnthonyWJones
+1 Thanks for confirming what i was suspecting and for going into details ! It makes perfect sense.
Gaby