1
1
'use strict' ;
2
2
3
- var TEST_REGEX = / ^ \$ | \. / ,
4
- REPLACE_REGEX = / ^ \$ | \. / g;
3
+ const TEST_REGEX = / ^ \$ | \. / ;
4
+ const REPLACE_REGEX = / ^ \$ | \. / g;
5
5
6
6
function isPlainObject ( obj ) {
7
7
return typeof obj === 'object' && obj !== null ;
8
8
}
9
9
10
10
function withEach ( target , cb ) {
11
- var act = function ( obj ) {
11
+ ( function act ( obj ) {
12
12
if ( Array . isArray ( obj ) ) {
13
13
obj . forEach ( act ) ;
14
14
15
15
} else if ( isPlainObject ( obj ) ) {
16
16
Object . keys ( obj ) . forEach ( function ( key ) {
17
- var val = obj [ key ] ;
18
- var resp = cb ( obj , val , key ) ;
17
+ const val = obj [ key ] ;
18
+ const resp = cb ( obj , val , key ) ;
19
19
if ( resp . shouldRecurse ) {
20
20
act ( obj [ resp . key || key ] ) ;
21
21
}
22
22
} ) ;
23
23
}
24
- } ;
24
+ } ) ( target ) ;
25
25
26
- act ( target ) ;
27
26
}
28
27
29
28
function has ( target ) {
30
- var hasProhibited = false ;
29
+ let hasProhibited = false ;
31
30
withEach ( target , function ( obj , val , key ) {
32
31
if ( TEST_REGEX . test ( key ) ) {
33
32
hasProhibited = true ;
@@ -43,13 +42,13 @@ function has(target) {
43
42
function sanitize ( target , options ) {
44
43
options = options || { } ;
45
44
46
- var replaceWith = null ;
45
+ let replaceWith = null ;
47
46
if ( ! ( TEST_REGEX . test ( options . replaceWith ) ) ) {
48
47
replaceWith = options . replaceWith ;
49
48
}
50
49
51
50
withEach ( target , function ( obj , val , key ) {
52
- var shouldRecurse = true ;
51
+ let shouldRecurse = true ;
53
52
54
53
if ( TEST_REGEX . test ( key ) ) {
55
54
delete obj [ key ] ;
@@ -72,7 +71,7 @@ function sanitize(target, options) {
72
71
73
72
function middleware ( options ) {
74
73
return function ( req , res , next ) {
75
- [ 'body' , 'params' , 'query' ] . forEach ( function ( k ) {
74
+ [ 'body' , 'params' , 'headers' , ' query'] . forEach ( function ( k ) {
76
75
if ( req [ k ] ) {
77
76
req [ k ] = sanitize ( req [ k ] , options ) ;
78
77
}
0 commit comments