query-string 9.4.1 → 9.5.1

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/base.js +19 -6
  2. package/package.json +2 -2
package/base.js CHANGED
@@ -395,10 +395,17 @@ export function parse(query, options) {
395
395
  return returnValue;
396
396
  }
397
397
 
398
- // Avoid `split('&')` so separator-heavy inputs don't allocate large arrays of empty strings.
398
+ if (/^&+$/.test(query)) {
399
+ return returnValue;
400
+ }
401
+
399
402
  let parameterStart = 0;
403
+ let firstSeparator = query.indexOf('&');
404
+ if (firstSeparator === -1) {
405
+ firstSeparator = query.length;
406
+ }
400
407
 
401
- for (let index = 0; index <= query.length; index++) {
408
+ for (let index = firstSeparator; index <= query.length; index++) {
402
409
  if (index < query.length && query[index] !== '&') {
403
410
  continue;
404
411
  }
@@ -409,7 +416,6 @@ export function parse(query, options) {
409
416
  }
410
417
 
411
418
  const parameter = query.slice(parameterStart, index);
412
- parameterStart = index + 1;
413
419
  const parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;
414
420
 
415
421
  let [key, value] = splitOnFirst(parameter_, '=');
@@ -422,6 +428,8 @@ export function parse(query, options) {
422
428
  // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
423
429
  value = value === undefined ? null : (['comma', 'separator', 'bracket-separator'].includes(options.arrayFormat) ? value : decode(value, options));
424
430
  formatter(decode(key, options), value, returnValue);
431
+
432
+ parameterStart = index + 1;
425
433
  }
426
434
 
427
435
  for (const [key, value] of Object.entries(returnValue)) {
@@ -571,9 +579,14 @@ export function stringifyUrl(object, options) {
571
579
 
572
580
  let hash = getHash(object.url);
573
581
  if (typeof object.fragmentIdentifier === 'string') {
574
- const urlObjectForFragmentEncode = new URL(url, 'https://query-string.invalid');
575
- urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
576
- hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : `#${object.fragmentIdentifier}`;
582
+ hash = `#${object.fragmentIdentifier}`;
583
+
584
+ if (options[encodeFragmentIdentifier]) {
585
+ // Percent-encode the fragment with a throwaway URL. The fragment percent-encode set does not depend on the scheme, so the caller's URL is deliberately not parsed here; it may not even be parseable.
586
+ const throwawayUrl = new URL('https://query-string.invalid');
587
+ throwawayUrl.hash = hash;
588
+ hash = throwawayUrl.hash;
589
+ }
577
590
  }
578
591
 
579
592
  return `${url}${queryString}${hash}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-string",
3
- "version": "9.4.1",
3
+ "version": "9.5.1",
4
4
  "description": "Parse and stringify URL query strings",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/query-string",
@@ -46,7 +46,7 @@
46
46
  "filter"
47
47
  ],
48
48
  "dependencies": {
49
- "decode-uri-component": "^0.4.1",
49
+ "decode-uri-component": "^0.5.0",
50
50
  "filter-obj": "^5.1.0",
51
51
  "split-on-first": "^3.0.0"
52
52
  },