IE 中的多个 @JS 注释错误

发布于 2024-09-26 13:36:07 字数 1547 浏览 0 评论 0原文

我在 IE 7、6.5(也许还有其他版本?)中遇到了一个错误/未记录的功能。这不会影响 Opera (10.5x) Firefox (3.5.x) 或任何其他浏览器(这是我迄今为止测试过的所有浏览器)。这似乎不是 Javascript 的记录能力。

通过包含由双斜杠表示的注释,并直接后跟双 at 符号 (//@@),整个 .js 文件将变得毫无用处。我检查了几个变体,这是我发现的(其中未加载fail=JS,加载了pass=JS):

  1. 失败://@@
  2. 失败:// @ @
  3. 失败://@@@ - 任何数量的 @ 似乎都没有影响
  4. 失败://@@ text - 任何内容以下似乎无助于
  5. 失败: //@hello@ - @ 之间的任何内容似乎无助于
  6. 通过: // @@
  7. pass: // @ @ - 第一个 @ 之前的空格似乎阻止
  8. 通过: //hello @@ - 第一个 @ 之前的任何内容似乎阻止
  9. 通过: /*@@*/ - 似乎仅适用于 // 注释样式

IE 7 - 只是忽略该文件,当尝试引用该文件的内容时,您会收到类似“”的错误<函数/对象>未定义”。 IE6.5可以正常报告“无效字符”,这大大提高了您发现问题的能力!

所以问题:有人知道为什么会发生这种情况以及发生了什么事吗?
您可以使用它(插入空格、使用其他注释样式等),但值得注意的是问题的存在,因为调试可能非常耗时。

更新: 如何重现:

来源:缺陷.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>

来源:缺陷.ie.js

//@@
alert('hello');

来源:turnon.cc.js

/*@cc_on
 @*/

结果:
IE:页面:世界
FF/Opera:警报:您好! page:World

潜在结论:在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白馒头 2024-10-03 13:36:07

我无法重现这个,也许这取决于你的环境。

看看这个:http://support.microsoft.com/kb/323487/en
或许有用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文