Multiple @ JS Comment bug in IE

≯℡__Kan透↙ 提交于 2019-12-22 07:37:19

问题


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.


回答1:


Most likely related to conditional comments:

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




回答2:


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



来源:https://stackoverflow.com/questions/3894079/multiple-js-comment-bug-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!