File tree 2 files changed +14
-1
lines changed
2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ const unescapeMap = {
35
35
'/' : '/'
36
36
}
37
37
38
+ const ownsProperty = Object . prototype . hasOwnProperty
39
+
38
40
function parseInternal ( input , options ) {
39
41
if ( typeof input !== 'string' || ! ( input instanceof String ) ) {
40
42
input = String ( input )
@@ -318,7 +320,7 @@ function parseInternal (input, options) {
318
320
while ( position < inputLength ) {
319
321
skipWhiteSpace ( )
320
322
const key = parseKey ( )
321
- if ( allowDuplicateObjectKeys === false && result [ key ] ) {
323
+ if ( allowDuplicateObjectKeys === false && ownsProperty . call ( result , key ) ) {
322
324
fail ( `Duplicate key: "${ key } "` )
323
325
}
324
326
skipWhiteSpace ( )
Original file line number Diff line number Diff line change @@ -157,6 +157,17 @@ test('duplicate keys', function () {
157
157
} )
158
158
} )
159
159
160
+ test ( 'no duplicate key "constructor"' , function ( ) {
161
+ assert . deepEqual ( parse ( '{ "constructor": 1 }' ) , { constructor : 1 } )
162
+ parse ( '{ "constructor": 1 }' , { allowDuplicateObjectKeys : false } )
163
+ } )
164
+
165
+ test ( 'no prototype pollution' , function ( ) {
166
+ const parsed = parse ( '{ "__proto__": { "polluted": true } }' )
167
+ assert . deepEqual ( parsed , JSON . parse ( '{ "__proto__": { "polluted": true } }' ) )
168
+ assert . notDeepEqual ( parsed , { polluted : true } )
169
+ } )
170
+
160
171
test ( 'random numbers' , function ( ) {
161
172
for ( let i = 0 ; i < 100 ; ++ i ) {
162
173
const str = '-01.e' . split ( '' )
You can’t perform that action at this time.
0 commit comments