Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint Regexp Violation Quandry

I have the following regular expresssion

/\<oauth_token\>([^\<]*)\<\/oauth_token\>/

I am seeing jslint violations for unescaped < characters, but can't work out why. Can anyone enlighten me please?

This regular expression is being assigned to a variable and is being used throughout the file. It is in a nodejs module.

This is a hack to get round a non-standards conformant OAUth response, which will be fixed at some point in the future. I do not want to bring in an XML parser as an extra dependency to solve the problem.

I am seeing this violation both with JSHint and node-jslint.

You can see the full source code for the file on github The exact output from JSHint is as follows:

lib/oauth-helper.js: line 5, col 21, Unexpected escaped character '<' in regular expression.
lib/oauth-helper.js: line 5, col 39, Unexpected escaped character '<' in regular expression.
lib/oauth-helper.js: line 5, col 44, Unexpected escaped character '<' in regular expression.
lib/oauth-helper.js: line 6, col 22, Unexpected escaped character '<' in regular expression.
lib/oauth-helper.js: line 6, col 47, Unexpected escaped character '<' in regular expression.
lib/oauth-helper.js: line 6, col 52, Unexpected escaped character '<' in regular expression.
like image 842
Raoul Avatar asked Aug 21 '11 14:08

Raoul


1 Answers

There's no need to escape the "<" character in a regular expression. That's what JSLint is telling you - that the backslashes before your "<" characters in the pattern are unnecessary.

like image 114
Pointy Avatar answered Nov 15 '22 13:11

Pointy