13

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?

Andrus
  • 26,339
  • 60
  • 204
  • 378

3 Answers3

18

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 */
James Lim
  • 12,915
  • 4
  • 40
  • 65
Pedro Polonia
  • 2,604
  • 3
  • 23
  • 31
17

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.

Wes
  • 186
  • 1
  • 3
  • A bit wacky but just what I needed. Thanks. – phatmann Oct 02 '12 at 19:46
  • 3
    I find it fascinating that jslint throws an error for what is a perfectly clear regular expression, but when you obfuscate what you are actually doing it is suddenly fine. – timgeb Apr 18 '15 at 13:39
  • that's why jshint was born AFAIK ,it's overzealous jslint but I use it anyway. I'm keeping the dot notation on this one – Glenn Plas Apr 18 '18 at 14:49
5

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.

JAAulde
  • 19,250
  • 5
  • 52
  • 63
  • 1
    As there is only one char, i'd say that `\s?` might be what he is looking for. – Py. Sep 08 '11 at 13:42
  • @Py: there may be attributes in body element so \s? cannot used. I updated question. – Andrus Sep 08 '11 at 14:01
  • @JAAulde: Thank you. I want to extract whole content inside body tags. javascript is running in browser, jquery is used. I updated question. – Andrus Sep 08 '11 at 14:03
  • disallowInsecureCharsInRegExp is the jslint maven configuration element. Set it to false to disable this check – Mark Chorley Jun 05 '13 at 15:55