File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
1
var safe = require ( 'safe-regex' ) ;
2
2
/**
3
3
* Check if the regex is evil or not using the safe-regex module
4
- * @author Adam Baldwin
4
+ * @author Adam Baldwin
5
5
*/
6
6
7
7
//------------------------------------------------------------------------------
@@ -11,9 +11,6 @@ var safe = require('safe-regex');
11
11
module . exports = function ( context ) {
12
12
13
13
"use strict" ;
14
- var getSource = function ( token ) {
15
- return token . loc . start . line + ': ' + context . getSourceLines ( ) . slice ( token . loc . start . line - 1 , token . loc . end . line ) . join ( '\n\t' ) ;
16
- }
17
14
18
15
return {
19
16
"Literal" : function ( node ) {
@@ -23,7 +20,14 @@ module.exports = function(context) {
23
20
24
21
if ( nodeType === "RegularExpression" ) {
25
22
if ( ! safe ( nodeValue ) ) {
26
- context . report ( node , "Unsafe Regular Expression\n" + getSource ( token ) ) ;
23
+ context . report ( node , "Unsafe Regular Expression" ) ;
24
+ }
25
+ }
26
+ } ,
27
+ "NewExpression" : function ( node ) {
28
+ if ( node . callee . name == "RegExp" && node . arguments && node . arguments . length > 0 && node . arguments [ 0 ] . type == "Literal" ) {
29
+ if ( ! safe ( node . arguments [ 0 ] . value ) ) {
30
+ context . report ( node , "Unsafe Regular Expression (new RegExp)" ) ;
27
31
}
28
32
}
29
33
}
You can’t perform that action at this time.
0 commit comments