@@ -11,7 +11,7 @@ module.exports = {
11
11
return replace . call ( value , percentTwenties , '+' ) ;
12
12
} ,
13
13
RFC3986 : function ( value ) {
14
- return value ;
14
+ return String ( value ) ;
15
15
}
16
16
} ,
17
17
RFC1738 : 'RFC1738' ,
@@ -102,7 +102,7 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
102
102
) {
103
103
obj = [ ] ;
104
104
obj [ index ] = parseObject ( chain , val , options ) ;
105
- } else {
105
+ } else if ( cleanRoot !== '__proto__' ) {
106
106
obj [ cleanRoot ] = parseObject ( chain , val , options ) ;
107
107
}
108
108
}
@@ -132,8 +132,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
132
132
133
133
var keys = [ ] ;
134
134
if ( parent ) {
135
- // If we aren't using plain objects, optionally prefix keys
136
- // that would overwrite object prototype properties
135
+ // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
137
136
if ( ! options . plainObjects && has . call ( Object . prototype , parent ) ) {
138
137
if ( ! options . allowPrototypes ) {
139
138
return ;
@@ -209,32 +208,38 @@ var utils = require('./utils');
209
208
var formats = require ( './formats' ) ;
210
209
211
210
var arrayPrefixGenerators = {
212
- brackets : function brackets ( prefix ) { // eslint-disable-line func-name-matching
211
+ brackets : function brackets ( prefix ) {
213
212
return prefix + '[]' ;
214
213
} ,
215
- indices : function indices ( prefix , key ) { // eslint-disable-line func-name-matching
214
+ indices : function indices ( prefix , key ) {
216
215
return prefix + '[' + key + ']' ;
217
216
} ,
218
- repeat : function repeat ( prefix ) { // eslint-disable-line func-name-matching
217
+ repeat : function repeat ( prefix ) {
219
218
return prefix ;
220
219
}
221
220
} ;
222
221
222
+ var isArray = Array . isArray ;
223
+ var push = Array . prototype . push ;
224
+ var pushToArray = function ( arr , valueOrArray ) {
225
+ push . apply ( arr , isArray ( valueOrArray ) ? valueOrArray : [ valueOrArray ] ) ;
226
+ } ;
227
+
223
228
var toISO = Date . prototype . toISOString ;
224
229
225
230
var defaults = {
226
231
delimiter : '&' ,
227
232
encode : true ,
228
233
encoder : utils . encode ,
229
234
encodeValuesOnly : false ,
230
- serializeDate : function serializeDate ( date ) { // eslint-disable-line func-name-matching
235
+ serializeDate : function serializeDate ( date ) {
231
236
return toISO . call ( date ) ;
232
237
} ,
233
238
skipNulls : false ,
234
239
strictNullHandling : false
235
240
} ;
236
241
237
- var stringify = function stringify ( // eslint-disable-line func-name-matching
242
+ var stringify = function stringify (
238
243
object ,
239
244
prefix ,
240
245
generateArrayPrefix ,
@@ -253,7 +258,9 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
253
258
obj = filter ( prefix , obj ) ;
254
259
} else if ( obj instanceof Date ) {
255
260
obj = serializeDate ( obj ) ;
256
- } else if ( obj === null ) {
261
+ }
262
+
263
+ if ( obj === null ) {
257
264
if ( strictNullHandling ) {
258
265
return encoder && ! encodeValuesOnly ? encoder ( prefix ) : prefix ;
259
266
}
@@ -276,7 +283,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
276
283
}
277
284
278
285
var objKeys ;
279
- if ( Array . isArray ( filter ) ) {
286
+ if ( isArray ( filter ) ) {
280
287
objKeys = filter ;
281
288
} else {
282
289
var keys = Object . keys ( obj ) ;
@@ -290,8 +297,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
290
297
continue ;
291
298
}
292
299
293
- if ( Array . isArray ( obj ) ) {
294
- values = values . concat ( stringify (
300
+ if ( isArray ( obj ) ) {
301
+ pushToArray ( values , stringify (
295
302
obj [ key ] ,
296
303
generateArrayPrefix ( prefix , key ) ,
297
304
generateArrayPrefix ,
@@ -306,7 +313,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
306
313
encodeValuesOnly
307
314
) ) ;
308
315
} else {
309
- values = values . concat ( stringify (
316
+ pushToArray ( values , stringify (
310
317
obj [ key ] ,
311
318
prefix + ( allowDots ? '.' + key : '[' + key + ']' ) ,
312
319
generateArrayPrefix ,
@@ -330,7 +337,7 @@ module.exports = function (object, opts) {
330
337
var obj = object ;
331
338
var options = opts || { } ;
332
339
333
- if ( options . encoder !== null && options . encoder !== undefined && typeof options . encoder !== 'function' ) {
340
+ if ( options . encoder !== null && typeof options . encoder !== ' undefined' && typeof options . encoder !== 'function' ) {
334
341
throw new TypeError ( 'Encoder has to be a function.' ) ;
335
342
}
336
343
@@ -344,7 +351,7 @@ module.exports = function (object, opts) {
344
351
var serializeDate = typeof options . serializeDate === 'function' ? options . serializeDate : defaults . serializeDate ;
345
352
var encodeValuesOnly = typeof options . encodeValuesOnly === 'boolean' ? options . encodeValuesOnly : defaults . encodeValuesOnly ;
346
353
if ( typeof options . format === 'undefined' ) {
347
- options . format = formats . default ;
354
+ options . format = formats [ ' default' ] ;
348
355
} else if ( ! Object . prototype . hasOwnProperty . call ( formats . formatters , options . format ) ) {
349
356
throw new TypeError ( 'Unknown format option provided.' ) ;
350
357
}
@@ -355,7 +362,7 @@ module.exports = function (object, opts) {
355
362
if ( typeof options . filter === 'function' ) {
356
363
filter = options . filter ;
357
364
obj = filter ( '' , obj ) ;
358
- } else if ( Array . isArray ( options . filter ) ) {
365
+ } else if ( isArray ( options . filter ) ) {
359
366
filter = options . filter ;
360
367
objKeys = filter ;
361
368
}
@@ -391,8 +398,7 @@ module.exports = function (object, opts) {
391
398
if ( skipNulls && obj [ key ] === null ) {
392
399
continue ;
393
400
}
394
-
395
- keys = keys . concat ( stringify (
401
+ pushToArray ( keys , stringify (
396
402
obj [ key ] ,
397
403
key ,
398
404
generateArrayPrefix ,
@@ -444,8 +450,8 @@ exports.merge = function (target, source, options) {
444
450
if ( typeof source !== 'object' ) {
445
451
if ( Array . isArray ( target ) ) {
446
452
target . push ( source ) ;
447
- } else if ( typeof target === 'object' ) {
448
- if ( options . plainObjects || options . allowPrototypes || ! has . call ( Object . prototype , source ) ) {
453
+ } else if ( target && typeof target === 'object' ) {
454
+ if ( ( options && ( options . plainObjects || options . allowPrototypes ) ) || ! has . call ( Object . prototype , source ) ) {
449
455
target [ source ] = true ;
450
456
}
451
457
} else {
@@ -455,7 +461,7 @@ exports.merge = function (target, source, options) {
455
461
return target ;
456
462
}
457
463
458
- if ( typeof target !== 'object' ) {
464
+ if ( ! target || typeof target !== 'object' ) {
459
465
return [ target ] . concat ( source ) ;
460
466
}
461
467
@@ -513,13 +519,13 @@ exports.encode = function (str) {
513
519
var c = string . charCodeAt ( i ) ;
514
520
515
521
if (
516
- c === 0x2D || // -
517
- c === 0x2E || // .
518
- c === 0x5F || // _
519
- c === 0x7E || // ~
520
- ( c >= 0x30 && c <= 0x39 ) || // 0-9
521
- ( c >= 0x41 && c <= 0x5A ) || // a-z
522
- ( c >= 0x61 && c <= 0x7A ) // A-Z
522
+ c === 0x2D // -
523
+ || c === 0x2E // .
524
+ || c === 0x5F // _
525
+ || c === 0x7E // ~
526
+ || ( c >= 0x30 && c <= 0x39 ) // 0-9
527
+ || ( c >= 0x41 && c <= 0x5A ) // a-z
528
+ || ( c >= 0x61 && c <= 0x7A ) // A-Z
523
529
) {
524
530
out += string . charAt ( i ) ;
525
531
continue ;
@@ -542,7 +548,11 @@ exports.encode = function (str) {
542
548
543
549
i += 1 ;
544
550
c = 0x10000 + ( ( ( c & 0x3FF ) << 10 ) | ( string . charCodeAt ( i ) & 0x3FF ) ) ;
545
- out += hexTable [ 0xF0 | ( c >> 18 ) ] + hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ] + hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] + hexTable [ 0x80 | ( c & 0x3F ) ] ; // eslint-disable-line max-len
551
+ /* eslint operator-linebreak: [2, "before"] */
552
+ out += hexTable [ 0xF0 | ( c >> 18 ) ]
553
+ + hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ]
554
+ + hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ]
555
+ + hexTable [ 0x80 | ( c & 0x3F ) ] ;
546
556
}
547
557
548
558
return out ;
0 commit comments