urlpurify 2.1.0 → 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/README.md CHANGED
@@ -39,7 +39,7 @@ cleanUrl(url, {
39
39
  // Names, or regexes tested on the lowercased name.
40
40
  trackingParams: [...defaultTrackingParams, 'newsletter_id', /^cmp_[a-z0-9_]+$/],
41
41
  // The default.
42
- maxUnwrapDepth: 6,
42
+ maxUnwrapDepth: 12,
43
43
  })
44
44
  ```
45
45
 
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;
@@ -70,7 +70,8 @@ const addMissingScheme = (target) => {
70
70
  };
71
71
  const applyUnwrappers = (url, unwrappers) => {
72
72
  for (const unwrap of unwrappers) {
73
- const raw = addMissingScheme(unwrap(url)?.trim());
73
+ const unwrapped = addMissingScheme(unwrap(url)?.trim());
74
+ const raw = unwrapped && !isHttpUrl(unwrapped) ? fixMalformedScheme(unwrapped) : unwrapped;
74
75
  if (!raw || !isHttpUrl(raw)) continue;
75
76
  const target = cleanTarget(raw);
76
77
  if (target) return target;
@@ -95,7 +96,7 @@ const stripTrackingParams = (url, trackingParams = defaultTrackingParams) => {
95
96
  const cleanUrl = (url, options) => {
96
97
  const unwrappers = options?.unwrappers ?? defaultUnwrappers;
97
98
  const trackingParams = options?.trackingParams ?? defaultTrackingParams;
98
- const maxUnwrapDepth = options?.maxUnwrapDepth ?? 6;
99
+ const maxUnwrapDepth = options?.maxUnwrapDepth ?? 12;
99
100
  const parsed = parseUrl(url);
100
101
  if (!parsed) return url;
101
102
  let currentParsed = parsed;
@@ -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.0"
48
+ "version": "2.1.2"
49
49
  }