9

この JavaScript コード (URL を参照する単なるコメント) が与えられた場合:

// see http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/

「セーフサブセット」がオンになっているJSLintは、

Dangerous comment.
// http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/

コメントはどのように危険なのですか? 定義上、コメントは解析されません。それとも彼らですか?

編集:別の URL を使用することは、必ずしも危険ではありません。たとえば、次のようになります。

// http://enterprisejquery.com

フラグをトリガーしません。コメント内の 1 つの URL が「危険」であるのに、別の URL はそうではないのはどうしてでしょうか?

4

2 に答える 2

3

「危険な」コメントは次の正規表現に一致します。

/@cc|<\/?|script|\]\s*\]|<\s*!|&lt/i

この場合、コメントに「スクリプト」という文字列が含まれているため、コメントは「危険」です。

これはおそらく誤検知だと思います。

于 2012-06-14T17:31:29.153 に答える
2

You can execute comments manually using eval:

http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.html

To combine all modules into a single resource, we wrote each module into a separate script tag and hid the code inside a comment block (/* */). When the resource first loads, none of the code is parsed since it is commented out. To load a module, find the DOM element for the corresponding script tag, strip out the comment block, and eval() the code.

Also, someone might accidently uncomment the dangerous code and create a vulnerability.

By default, no, JavaScript comments are not parsed. But there are not a nice thing to have lying around.

于 2012-06-14T17:15:04.200 に答える