query-string 6.13.5 → 6.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +20 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -122,8 +122,10 @@ function parserForArrayFormat(options) {
122
122
  case 'comma':
123
123
  case 'separator':
124
124
  return (key, value, accumulator) => {
125
- const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1;
126
- const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
125
+ const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
126
+ const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
127
+ value = isEncodedArray ? decode(value, options) : value;
128
+ const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
127
129
  accumulator[key] = newValue;
128
130
  };
129
131
 
@@ -214,7 +216,7 @@ function parseValue(value, options) {
214
216
  return value;
215
217
  }
216
218
 
217
- function parse(input, options) {
219
+ function parse(query, options) {
218
220
  options = Object.assign({
219
221
  decode: true,
220
222
  sort: true,
@@ -231,17 +233,17 @@ function parse(input, options) {
231
233
  // Create an object with no prototype
232
234
  const ret = Object.create(null);
233
235
 
234
- if (typeof input !== 'string') {
236
+ if (typeof query !== 'string') {
235
237
  return ret;
236
238
  }
237
239
 
238
- input = input.trim().replace(/^[?#&]/, '');
240
+ query = query.trim().replace(/^[?#&]/, '');
239
241
 
240
- if (!input) {
242
+ if (!query) {
241
243
  return ret;
242
244
  }
243
245
 
244
- for (const param of input.split('&')) {
246
+ for (const param of query.split('&')) {
245
247
  let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
246
248
 
247
249
  // Missing `=` should be `null`:
@@ -337,41 +339,41 @@ exports.stringify = (object, options) => {
337
339
  }).filter(x => x.length > 0).join('&');
338
340
  };
339
341
 
340
- exports.parseUrl = (input, options) => {
342
+ exports.parseUrl = (url, options) => {
341
343
  options = Object.assign({
342
344
  decode: true
343
345
  }, options);
344
346
 
345
- const [url, hash] = splitOnFirst(input, '#');
347
+ const [url_, hash] = splitOnFirst(url, '#');
346
348
 
347
349
  return Object.assign(
348
350
  {
349
- url: url.split('?')[0] || '',
350
- query: parse(extract(input), options)
351
+ url: url_.split('?')[0] || '',
352
+ query: parse(extract(url), options)
351
353
  },
352
354
  options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
353
355
  );
354
356
  };
355
357
 
356
- exports.stringifyUrl = (input, options) => {
358
+ exports.stringifyUrl = (object, options) => {
357
359
  options = Object.assign({
358
360
  encode: true,
359
361
  strict: true
360
362
  }, options);
361
363
 
362
- const url = removeHash(input.url).split('?')[0] || '';
363
- const queryFromUrl = exports.extract(input.url);
364
+ const url = removeHash(object.url).split('?')[0] || '';
365
+ const queryFromUrl = exports.extract(object.url);
364
366
  const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
365
367
 
366
- const query = Object.assign(parsedQueryFromUrl, input.query);
368
+ const query = Object.assign(parsedQueryFromUrl, object.query);
367
369
  let queryString = exports.stringify(query, options);
368
370
  if (queryString) {
369
371
  queryString = `?${queryString}`;
370
372
  }
371
373
 
372
- let hash = getHash(input.url);
373
- if (input.fragmentIdentifier) {
374
- hash = `#${encode(input.fragmentIdentifier, options)}`;
374
+ let hash = getHash(object.url);
375
+ if (object.fragmentIdentifier) {
376
+ hash = `#${encode(object.fragmentIdentifier, options)}`;
375
377
  }
376
378
 
377
379
  return `${url}${queryString}${hash}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-string",
3
- "version": "6.13.5",
3
+ "version": "6.13.6",
4
4
  "description": "Parse and stringify URL query strings",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/query-string",