Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix jslint message Insecure '.'

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?

like image 428
Andrus Avatar asked Sep 08 '11 12:09

Andrus


3 Answers

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 */
like image 146
Pedro Polonia Avatar answered Oct 17 '22 19:10

Pedro Polonia


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.

like image 40
Wes Avatar answered Oct 17 '22 21:10

Wes


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.

like image 5
JAAulde Avatar answered Oct 17 '22 19:10

JAAulde