query-string 9.5.0 → 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 +8 -3
  2. package/package.json +1 -1
package/base.js CHANGED
@@ -579,9 +579,14 @@ export function stringifyUrl(object, options) {
579
579
 
580
580
  let hash = getHash(object.url);
581
581
  if (typeof object.fragmentIdentifier === 'string') {
582
- const urlObjectForFragmentEncode = new URL(url, 'https://query-string.invalid');
583
- urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
584
- 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
+ }
585
590
  }
586
591
 
587
592
  return `${url}${queryString}${hash}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-string",
3
- "version": "9.5.0",
3
+ "version": "9.5.1",
4
4
  "description": "Parse and stringify URL query strings",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/query-string",