urlpurify 2.1.1 → 2.1.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.
package/dist/clean.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { fixMalformedProtocol, isHttpUrl, isIpAddress, normalizeUrl, parseUrl, stripWww } from "./node_modules/trousse/dist/urls.mjs";
1
+ import { fixMalformedScheme, isHttpUrl, isIpAddress, normalizeUrl, parseUrl, stripWww } from "./node_modules/trousse/dist/urls.mjs";
2
2
  import { defaultTrackingParams, defaultUnwrappers } from "./defaults.mjs";
3
3
  //#region src/clean.ts
4
4
  const refDelimitersRegex = /[\s/?#\\:@]/;
@@ -53,7 +53,7 @@ const dottedHostRegex = /[^.]\.[^.]/;
53
53
  const fileExtensionHostRegex = /\.(?:asp|aspx|cgi|htm|html|jsp|jspa|php)$/;
54
54
  const cleanTarget = (target) => {
55
55
  if (!target) return;
56
- const repaired = fixMalformedProtocol(target.trim());
56
+ const repaired = fixMalformedScheme(target.trim());
57
57
  if (controlCharactersRegex.test(repaired)) return;
58
58
  const hostname = parseUrl(repaired)?.hostname ?? "";
59
59
  if (!dottedHostRegex.test(hostname) && !isIpAddress(hostname)) return;
@@ -68,14 +68,10 @@ const addMissingScheme = (target) => {
68
68
  if (bareHostRegex.test(target)) return `https://${target}`;
69
69
  return target;
70
70
  };
71
- const schemeSpacingRegex = /^(https?:\/\/)(?:%20|\s|\+)+/i;
72
- const repairSchemeSpacing = (target) => {
73
- if (!target || !schemeSpacingRegex.test(target)) return target;
74
- return fixMalformedProtocol(target.replace(schemeSpacingRegex, "$1"));
75
- };
76
71
  const applyUnwrappers = (url, unwrappers) => {
77
72
  for (const unwrap of unwrappers) {
78
- const raw = repairSchemeSpacing(addMissingScheme(unwrap(url)?.trim()));
73
+ const unwrapped = addMissingScheme(unwrap(url)?.trim());
74
+ const raw = unwrapped && !isHttpUrl(unwrapped) ? fixMalformedScheme(unwrapped) : unwrapped;
79
75
  if (!raw || !isHttpUrl(raw)) continue;
80
76
  const target = cleanTarget(raw);
81
77
  if (target) return target;
@@ -102,7 +102,8 @@ const relativeLeadChars = [
102
102
  const localhostRegex = /^localhost(?:[:/?#]|$)/i;
103
103
  const validUrlRegex = /^https?:\/\/(?:www\.|[a-vx-z0-9])/i;
104
104
  const schemeSeparator = String.raw`\.*[:\s=\\/][:\s=.\\/]*`;
105
- const leadingSchemeSeparator = String.raw`\.*(?::[:\s=.\\/]*|[\s=\\/][:\s=.\\/]+)`;
105
+ const separatorChar = String.raw`(?:[:\s=.\\/]|%20|%c2%a0)`;
106
+ const leadingSchemeSeparator = String.raw`\.*(?::${separatorChar}*|[\s=\\/]${separatorChar}+)`;
106
107
  const doubledSchemeRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?[htps]{2,7}${leadingSchemeSeparator}([htps]{2,7})(?!:\d|[^/?#\\]*@)(${schemeSeparator})[.,:/]*(www[./]+)?`, "i");
107
108
  const singleMalformedRegex = /* @__PURE__ */ new RegExp(String.raw`^\/?(h[htps():]{1,10}|t{1,2}ps?)(${leadingSchemeSeparator})[.,:/]*(www[./]+)?`, "i");
108
109
  const isSchemeToken = (token, separator) => {
@@ -227,9 +228,7 @@ const stripWww = (hostname) => {
227
228
  const isIpAddress = (hostname) => {
228
229
  return ipv4Regex.test(hostname) || ipv6Regex.test(hostname.replace(ipv6BracketsRegex, ""));
229
230
  };
230
- /** @deprecated Use `fixMalformedScheme` instead. */
231
- const fixMalformedProtocol = fixMalformedScheme;
232
231
  /** @deprecated Use `addMissingScheme` instead. */
233
232
  const addMissingProtocol = addMissingScheme;
234
233
  //#endregion
235
- export { addMissingProtocol, addMissingScheme, decodePercent, fixMalformedProtocol, fixMalformedScheme, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, stripWww };
234
+ export { addMissingProtocol, addMissingScheme, decodePercent, fixMalformedScheme, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, stripWww };
package/package.json CHANGED
@@ -42,8 +42,8 @@
42
42
  "devDependencies": {
43
43
  "@types/bun": "^1.4.2",
44
44
  "kvalita": "^1.24.3",
45
- "trousse": "^2.15.0",
45
+ "trousse": "^2.15.1",
46
46
  "tsdown": "^0.23.0"
47
47
  },
48
- "version": "2.1.1"
48
+ "version": "2.1.2"
49
49
  }