@@ -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,31 +208,37 @@ 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
- serializeDate : function serializeDate ( date ) { // eslint-disable-line func-name-matching
234
+ serializeDate : function serializeDate ( date ) {
230
235
return toISO . call ( date ) ;
231
236
} ,
232
237
skipNulls : false ,
233
238
strictNullHandling : false
234
239
} ;
235
240
236
- var stringify = function stringify ( // eslint-disable-line func-name-matching
241
+ var stringify = function stringify (
237
242
object ,
238
243
prefix ,
239
244
generateArrayPrefix ,
@@ -251,7 +256,9 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
251
256
obj = filter ( prefix , obj ) ;
252
257
} else if ( obj instanceof Date ) {
253
258
obj = serializeDate ( obj ) ;
254
- } else if ( obj === null ) {
259
+ }
260
+
261
+ if ( obj === null ) {
255
262
if ( strictNullHandling ) {
256
263
return encoder ? encoder ( prefix ) : prefix ;
257
264
}
@@ -273,7 +280,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
273
280
}
274
281
275
282
var objKeys ;
276
- if ( Array . isArray ( filter ) ) {
283
+ if ( isArray ( filter ) ) {
277
284
objKeys = filter ;
278
285
} else {
279
286
var keys = Object . keys ( obj ) ;
@@ -287,8 +294,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
287
294
continue ;
288
295
}
289
296
290
- if ( Array . isArray ( obj ) ) {
291
- values = values . concat ( stringify (
297
+ if ( isArray ( obj ) ) {
298
+ pushToArray ( values , stringify (
292
299
obj [ key ] ,
293
300
generateArrayPrefix ( prefix , key ) ,
294
301
generateArrayPrefix ,
@@ -302,7 +309,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
302
309
formatter
303
310
) ) ;
304
311
} else {
305
- values = values . concat ( stringify (
312
+ pushToArray ( values , stringify (
306
313
obj [ key ] ,
307
314
prefix + ( allowDots ? '.' + key : '[' + key + ']' ) ,
308
315
generateArrayPrefix ,
@@ -325,20 +332,20 @@ module.exports = function (object, opts) {
325
332
var obj = object ;
326
333
var options = opts || { } ;
327
334
328
- if ( options . encoder !== null && options . encoder !== undefined && typeof options . encoder !== 'function' ) {
335
+ if ( options . encoder !== null && typeof options . encoder !== ' undefined' && typeof options . encoder !== 'function' ) {
329
336
throw new TypeError ( 'Encoder has to be a function.' ) ;
330
337
}
331
338
332
339
var delimiter = typeof options . delimiter === 'undefined' ? defaults . delimiter : options . delimiter ;
333
340
var strictNullHandling = typeof options . strictNullHandling === 'boolean' ? options . strictNullHandling : defaults . strictNullHandling ;
334
341
var skipNulls = typeof options . skipNulls === 'boolean' ? options . skipNulls : defaults . skipNulls ;
335
342
var encode = typeof options . encode === 'boolean' ? options . encode : defaults . encode ;
336
- var encoder = encode ? ( typeof options . encoder === 'function' ? options . encoder : defaults . encoder ) : null ;
343
+ var encoder = encode ? typeof options . encoder === 'function' ? options . encoder : defaults . encoder : null ;
337
344
var sort = typeof options . sort === 'function' ? options . sort : null ;
338
345
var allowDots = typeof options . allowDots === 'undefined' ? false : options . allowDots ;
339
346
var serializeDate = typeof options . serializeDate === 'function' ? options . serializeDate : defaults . serializeDate ;
340
347
if ( typeof options . format === 'undefined' ) {
341
- options . format = formats . default ;
348
+ options . format = formats [ ' default' ] ;
342
349
} else if ( ! Object . prototype . hasOwnProperty . call ( formats . formatters , options . format ) ) {
343
350
throw new TypeError ( 'Unknown format option provided.' ) ;
344
351
}
@@ -349,7 +356,7 @@ module.exports = function (object, opts) {
349
356
if ( typeof options . filter === 'function' ) {
350
357
filter = options . filter ;
351
358
obj = filter ( '' , obj ) ;
352
- } else if ( Array . isArray ( options . filter ) ) {
359
+ } else if ( isArray ( options . filter ) ) {
353
360
filter = options . filter ;
354
361
objKeys = filter ;
355
362
}
@@ -385,8 +392,7 @@ module.exports = function (object, opts) {
385
392
if ( skipNulls && obj [ key ] === null ) {
386
393
continue ;
387
394
}
388
-
389
- keys = keys . concat ( stringify (
395
+ pushToArray ( keys , stringify (
390
396
obj [ key ] ,
391
397
key ,
392
398
generateArrayPrefix ,
@@ -437,8 +443,8 @@ exports.merge = function (target, source, options) {
437
443
if ( typeof source !== 'object' ) {
438
444
if ( Array . isArray ( target ) ) {
439
445
target . push ( source ) ;
440
- } else if ( typeof target === 'object' ) {
441
- if ( options . plainObjects || options . allowPrototypes || ! has . call ( Object . prototype , source ) ) {
446
+ } else if ( target && typeof target === 'object' ) {
447
+ if ( ( options && ( options . plainObjects || options . allowPrototypes ) ) || ! has . call ( Object . prototype , source ) ) {
442
448
target [ source ] = true ;
443
449
}
444
450
} else {
@@ -448,7 +454,7 @@ exports.merge = function (target, source, options) {
448
454
return target ;
449
455
}
450
456
451
- if ( typeof target !== 'object' ) {
457
+ if ( ! target || typeof target !== 'object' ) {
452
458
return [ target ] . concat ( source ) ;
453
459
}
454
460
@@ -506,13 +512,13 @@ exports.encode = function (str) {
506
512
var c = string . charCodeAt ( i ) ;
507
513
508
514
if (
509
- c === 0x2D || // -
510
- c === 0x2E || // .
511
- c === 0x5F || // _
512
- c === 0x7E || // ~
513
- ( c >= 0x30 && c <= 0x39 ) || // 0-9
514
- ( c >= 0x41 && c <= 0x5A ) || // a-z
515
- ( c >= 0x61 && c <= 0x7A ) // A-Z
515
+ c === 0x2D // -
516
+ || c === 0x2E // .
517
+ || c === 0x5F // _
518
+ || c === 0x7E // ~
519
+ || ( c >= 0x30 && c <= 0x39 ) // 0-9
520
+ || ( c >= 0x41 && c <= 0x5A ) // a-z
521
+ || ( c >= 0x61 && c <= 0x7A ) // A-Z
516
522
) {
517
523
out += string . charAt ( i ) ;
518
524
continue ;
@@ -535,7 +541,11 @@ exports.encode = function (str) {
535
541
536
542
i += 1 ;
537
543
c = 0x10000 + ( ( ( c & 0x3FF ) << 10 ) | ( string . charCodeAt ( i ) & 0x3FF ) ) ;
538
- out += hexTable [ 0xF0 | ( c >> 18 ) ] + hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ] + hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ] + hexTable [ 0x80 | ( c & 0x3F ) ] ; // eslint-disable-line max-len
544
+ /* eslint operator-linebreak: [2, "before"] */
545
+ out += hexTable [ 0xF0 | ( c >> 18 ) ]
546
+ + hexTable [ 0x80 | ( ( c >> 12 ) & 0x3F ) ]
547
+ + hexTable [ 0x80 | ( ( c >> 6 ) & 0x3F ) ]
548
+ + hexTable [ 0x80 | ( c & 0x3F ) ] ;
539
549
}
540
550
541
551
return out ;
0 commit comments