trousse 2.14.0 → 2.14.2

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/dist/urls.js +20 -8
  2. package/package.json +1 -1
package/dist/urls.js CHANGED
@@ -382,20 +382,32 @@ const sameQuerySpellings = [
382
382
  ["@", "%40"]
383
383
  ];
384
384
  const percentEscapeRegex = /%[0-9a-f]{2}/gi;
385
+ const addLowercaseHexSpellings = (url, spellings) => {
386
+ if (url.search(percentEscapeRegex) === -1) return [...new Set(spellings)];
387
+ const lowercaseHexSpellings = spellings.map((spelling) => {
388
+ return spelling.replace(percentEscapeRegex, (hex) => hex.toLowerCase());
389
+ });
390
+ return [.../* @__PURE__ */ new Set([...spellings, ...lowercaseHexSpellings])];
391
+ };
385
392
  const createUrlSpellings = (url) => {
386
- const spellings = [url, url.replace(percentEscapeRegex, (hex) => hex.toUpperCase())];
393
+ const uppercaseHexUrl = url.replace(percentEscapeRegex, (hex) => hex.toUpperCase());
394
+ let spellings = [.../* @__PURE__ */ new Set([url, uppercaseHexUrl])];
387
395
  const hashIndex = url.indexOf("#");
388
396
  const queryEnd = hashIndex === -1 ? url.length : hashIndex;
389
397
  const queryIndex = url.indexOf("?");
390
- if (queryIndex === -1 || queryIndex > queryEnd) return [...new Set(spellings)];
391
- const head = url.slice(0, queryIndex);
392
- const query = url.slice(queryIndex, queryEnd);
393
- const fragment = url.slice(queryEnd);
398
+ if (queryIndex === -1 || queryIndex > queryEnd) return addLowercaseHexSpellings(url, spellings);
394
399
  for (const [written, encoded] of sameQuerySpellings) {
395
- spellings.push(`${head}${query.replaceAll(written, encoded)}${fragment}`);
396
- spellings.push(`${head}${query.replaceAll(encoded, written)}${fragment}`);
400
+ const swapped = spellings.flatMap((spelling) => {
401
+ const fragmentIndex = spelling.indexOf("#");
402
+ const spellingQueryEnd = fragmentIndex === -1 ? spelling.length : fragmentIndex;
403
+ const head = spelling.slice(0, queryIndex);
404
+ const query = spelling.slice(queryIndex, spellingQueryEnd);
405
+ const fragment = spelling.slice(spellingQueryEnd);
406
+ return [`${head}${query.replaceAll(encoded, written)}${fragment}`, `${head}${query.replaceAll(written, encoded)}${fragment}`];
407
+ });
408
+ spellings = [...new Set(swapped)];
397
409
  }
398
- return [...new Set(spellings)];
410
+ return addLowercaseHexSpellings(url, [url, ...spellings]);
399
411
  };
400
412
  const genericSecondLevels = [
401
413
  "ac",
package/package.json CHANGED
@@ -46,5 +46,5 @@
46
46
  "dependencies": {
47
47
  "entities": "^8.1.0"
48
48
  },
49
- "version": "2.14.0"
49
+ "version": "2.14.2"
50
50
  }