how to fix jslint message Insecure '.'

◇◆丶佛笑我妖孽 提交于 2019-12-30 05:56:06

问题


jslint reports message Insecure '.'.

at line

html = /<body.*?>([\s\S]*)<\/body>/.exec(responseText);

How to fix this ?

Update

After body and before closing bracket there may be attributes so \s? cannot used. Javascript is running in browser, jQuery is used. Which is best way to extract body element content from string instead of this?


回答1:


You may try something like this if you really want it to match everything and don't want the jslint error.

var everything = /.*?/;// not jslint acceptable
var all = /[\w\W]*?/;// jslint acceptable

basically it says any word character and any non-word character... which pretty much covers everything.




回答2:


You can add regexp: true to jsLint options. Just add a line to your javascript file like:

/*jslint indent: 4, maxerr: 50, vars: true, regexp: true, sloppy: true */



回答3:


That check in JSLint is there because if you allow for any char (.), or any char except some specified ([^x]), you could get matches you weren't expecting. If you have that check turned on in JSLint, you need to be writing regexes which explicitly state what should be matching.

If you don't want to turn off that check, and you want an error free LINT, determine what would you consider as OK to be found between the 'y' of 'body' and the closing angle bracket, and write your regex in that manner.



来源:https://stackoverflow.com/questions/7348028/how-to-fix-jslint-message-insecure

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