File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ module.exports = function(string) {
19
19
for ( var j = 0 ; j < levels . length ; j ++ ) {
20
20
var level = levels [ j ] , nextLevel = levels [ j + 1 ]
21
21
var isNumber = nextLevel == "" || ! isNaN ( parseInt ( nextLevel , 10 ) )
22
- var isValue = j === levels . length - 1
23
22
if ( level === "" ) {
24
23
var key = levels . slice ( 0 , j ) . join ( )
25
24
if ( counters [ key ] == null ) {
@@ -29,15 +28,15 @@ module.exports = function(string) {
29
28
}
30
29
// Disallow direct prototype pollution
31
30
else if ( level === "__proto__" ) break
32
- if ( isValue ) cursor [ level ] = value
31
+ if ( j === levels . length - 1 ) cursor [ level ] = value
33
32
else {
34
33
// Read own properties exclusively to disallow indirect
35
34
// prototype pollution
36
- value = Object . getOwnPropertyDescriptor ( cursor , level )
37
- if ( value != null ) value = value . value
38
- if ( value == null ) value = cursor [ level ] = isNumber ? [ ] : { }
35
+ var desc = Object . getOwnPropertyDescriptor ( cursor , level )
36
+ if ( desc != null ) desc = desc . value
37
+ if ( desc == null ) cursor [ level ] = desc = isNumber ? [ ] : { }
38
+ cursor = desc
39
39
}
40
- cursor = value
41
40
}
42
41
}
43
42
return data
Original file line number Diff line number Diff line change @@ -105,8 +105,11 @@ o.spec("parseQueryString", function() {
105
105
} )
106
106
o ( "doesn't pollute prototype indirectly, retains `constructor`" , function ( ) {
107
107
var prev = Object . prototype . toString
108
- var data = parseQueryString ( "constructor%5Bprototype%5D%5BtoString%5D=123" )
108
+ var data = parseQueryString ( "a=b& constructor%5Bprototype%5D%5BtoString%5D=123" )
109
109
o ( Object . prototype . toString ) . equals ( prev )
110
- o ( data ) . deepEquals ( { a : "b" } )
110
+ // The deep matcher is borked here.
111
+ o ( Object . keys ( data ) ) . deepEquals ( [ "a" , "constructor" ] )
112
+ o ( data . a ) . equals ( "b" )
113
+ o ( data . constructor ) . deepEquals ( { prototype : { toString : "123" } } )
111
114
} )
112
115
} )
You can’t perform that action at this time.
0 commit comments