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 +1 -1
- package/dist/clean.mjs +5 -4
- package/dist/node_modules/trousse/dist/urls.mjs +3 -4
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/clean.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
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
|
|
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 ??
|
|
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
|
|
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,
|
|
234
|
+
export { addMissingProtocol, addMissingScheme, decodePercent, fixMalformedScheme, isHostOf, isHostOrSubdomainOf, isHttpUrl, isIpAddress, isSubdomainOf, normalizeUrl, parseUrl, stripWww };
|