Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple @ JS Comment bug in IE

I've come across a bug/undocumented feature in IE 7, 6.5 (perhaps others?). This doesn't effect Opera (10.5x) Firefox (3.5.x) or likely any other browser (this is all I've tested so far). It doesn't seem to be a documented ability of Javascript.

By including a comment denoted by double slashes, and directly followed by double at signs (//@@), the whole .js file is rendered useless. I've checked several variations and here's what I've found (where fail=JS isn't loaded, pass=JS is loaded):

  1. fail: //@@
  2. fail: //@ @
  3. fail: //@@@ - any number of @ doesn't seem to make a difference
  4. fail: //@@ text - any content following doesn't seem to help
  5. fail: //@hello@ - any content between @ doesn't seem to help
  6. pass: // @@
  7. pass: // @ @ - space before first @ seems to prevent
  8. pass: //hello @@ - any content before first @ seems to prevent
  9. pass: /*@@*/ - only seems to apply to // comment style

IE 7 - just ignores the file, when trying to reference the content of that file you get an error along the lines of "<function/object> is undefined". IE6.5 has the decency to report "Invalid character" which significantly improves your ability to find the problem!

And so the question: Does anyone know why this is happening and what's going on?
You can work with it (insert a space, use the other comment style etc) but it's worth noting the problem's there, since can be time-consuming to debug.

UPDATE: How to reproduce:

Source: flaw.ie.html

<html lang="en">
  <head>
    <title>Test</title>
    <script src="turnon.cc.js"></script>
    <script src="flaw.ie.js"></script>
  </head>
  <body>
    World
  </body>
</html>

Source: flaw.ie.js

//@@
alert('hello');

Source: turnon.cc.js

/*@cc_on
 @*/

Result:
IE: page:World
FF/Opera: Alert:Hello! page:World

Potential conclusion: Once conditional compilation is turned on in IE, be careful with comments that vaguely resemble the syntax.

like image 822
Rudu Avatar asked Oct 08 '10 20:10

Rudu


1 Answers

Most likely related to conditional comments:

http://www.javascriptkit.com/javatutors/conditionalcompile.shtml

like image 84
methodin Avatar answered Oct 03 '22 17:10

methodin