views:

33

answers:

2

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.

+2  A: 

Most likely related to conditional comments:

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

methodin
That looks promising - we're certainly finding a use for @ in comments in JS... however all examples (I can find) are show use in `/**/` comments (alone) and it's supposed to only operate after you've turned conditional compile on (`@cc_on`) - it's supposed to ignore them otherwise. That's a pretty major flaw in their parsing algorithm if `/*@@*/` comments work but `//@@` don't.
Rudu
Ah ha! While writing out code to reproduce the issue (thanks @Dr.Molle), I discovered the use of the library `modernizer-1.5.min.js` (unmodified) was making a difference - low and behold, `/@cc_on` can be found in there (line 20, char 95) - so conditional comments seem to be the start of the problem - once they're on, don't use `//@@`. Illogically `/*@@*/` is still ok.
Rudu
+1  A: 

I cannot reproduce this, maybe it depends on your environment.

Take a look at this: http://support.microsoft.com/kb/323487/en Maybe it's useful

Dr.Molle
It's uncompiled/uninterpretted code (.html file, with .css and .js includes). [running through Apache for the record] But that JScript .NET error for case #3 sounds suspiciously familiar - which would imply JScript.NET is being (incorrectly) used instead of Javascript (where @ has no meaning)
Rudu