trousse 3.19.0 → 3.19.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/urls.js +18 -13
- package/package.json +2 -2
package/dist/urls.js
CHANGED
|
@@ -144,7 +144,7 @@ const decodePercent = (value) => {
|
|
|
144
144
|
};
|
|
145
145
|
const decodeBase64Binary = (value) => {
|
|
146
146
|
try {
|
|
147
|
-
return atob(value);
|
|
147
|
+
return atob(value.replaceAll(" ", "+"));
|
|
148
148
|
} catch {}
|
|
149
149
|
};
|
|
150
150
|
const utf8Decoder = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
|
|
@@ -162,7 +162,7 @@ const decodeBase64 = (value) => {
|
|
|
162
162
|
let encoded = "";
|
|
163
163
|
for (let index = 0; index < binary.length; index++) {
|
|
164
164
|
const byte = binary.charCodeAt(index);
|
|
165
|
-
if (byte < 128 && binary
|
|
165
|
+
if (byte < 128 && !binary.startsWith("%", index)) {
|
|
166
166
|
encoded += binary[index];
|
|
167
167
|
continue;
|
|
168
168
|
}
|
|
@@ -183,7 +183,10 @@ const pathSegmentEscapeRegex = /[/?#\\\s]/g;
|
|
|
183
183
|
const encodePathSegment = (value) => {
|
|
184
184
|
return value.replace(pathSegmentEscapeRegex, (character) => encodeURIComponent(character));
|
|
185
185
|
};
|
|
186
|
-
const
|
|
186
|
+
const decodeFormPart = (part) => {
|
|
187
|
+
return decodePercent(part.replaceAll("+", " "));
|
|
188
|
+
};
|
|
189
|
+
const readPairs = (text, prefix, options) => {
|
|
187
190
|
if (text === void 0) return;
|
|
188
191
|
const pairs = [];
|
|
189
192
|
const body = text.startsWith(prefix) ? text.slice(1) : text;
|
|
@@ -191,24 +194,25 @@ const readRawPairs = (text, prefix) => {
|
|
|
191
194
|
if (!pair) continue;
|
|
192
195
|
const separator = pair.indexOf("=");
|
|
193
196
|
if (separator === -1) {
|
|
194
|
-
pairs.push([
|
|
197
|
+
pairs.push([decodeFormPart(pair), ""]);
|
|
195
198
|
continue;
|
|
196
199
|
}
|
|
197
|
-
const name =
|
|
198
|
-
|
|
200
|
+
const name = decodeFormPart(pair.slice(0, separator));
|
|
201
|
+
const value = pair.slice(separator + 1);
|
|
202
|
+
pairs.push([name, options?.decodeValues === false ? value : decodeFormPart(value)]);
|
|
199
203
|
}
|
|
200
204
|
return pairs;
|
|
201
205
|
};
|
|
202
206
|
const readQuerySource = (source, options) => {
|
|
203
|
-
if (options?.decodeValues === false) return
|
|
204
|
-
if (source instanceof URL) return source.
|
|
205
|
-
if (isString(source)) return
|
|
207
|
+
if (options?.decodeValues === false) return readPairs(source instanceof URL ? source.search : source?.toString(), "?", options);
|
|
208
|
+
if (source instanceof URL) return readPairs(source.search, "?", options);
|
|
209
|
+
if (isString(source)) return readPairs(source, "?", options);
|
|
206
210
|
return source;
|
|
207
211
|
};
|
|
208
212
|
const readFragmentSource = (source, options) => {
|
|
209
|
-
if (options?.decodeValues === false) return
|
|
210
|
-
if (source instanceof URL) return
|
|
211
|
-
if (isString(source)) return
|
|
213
|
+
if (options?.decodeValues === false) return readPairs(source instanceof URL ? source.hash : source?.toString(), "#", options);
|
|
214
|
+
if (source instanceof URL) return readPairs(source.hash.slice(1), "?", options);
|
|
215
|
+
if (isString(source)) return readPairs(source.startsWith("#") ? source.slice(1) : source, "?", options);
|
|
212
216
|
return source;
|
|
213
217
|
};
|
|
214
218
|
const readParamValues = (params, name, options) => {
|
|
@@ -320,6 +324,7 @@ const relativeLeadChars = [
|
|
|
320
324
|
"#"
|
|
321
325
|
];
|
|
322
326
|
const localhostRegex = /^localhost(?:[:/?#]|$)/i;
|
|
327
|
+
const portRegex = /^\d+(?:[/?#]|$)/;
|
|
323
328
|
const schemeColonRegex = /^[^/]*:/;
|
|
324
329
|
const missingColonSchemeRegex = /^https?[\s=.\\]*\/\//i;
|
|
325
330
|
const validUrlRegex = /^https?:\/\/(?:www\.|[a-vx-z0-9])/i;
|
|
@@ -491,7 +496,7 @@ const addMissingScheme = (url, scheme = "https") => {
|
|
|
491
496
|
const colonIndex = url.indexOf(":");
|
|
492
497
|
if (colonIndex > 0) {
|
|
493
498
|
const beforeColon = url.slice(0, colonIndex);
|
|
494
|
-
if (!beforeColon.includes(".") && !beforeColon.includes("/") && !localhostRegex.test(url)) return url;
|
|
499
|
+
if (!(beforeColon.includes(".") && portRegex.test(url.slice(colonIndex + 1))) && !beforeColon.includes("/") && !localhostRegex.test(url)) return url;
|
|
495
500
|
}
|
|
496
501
|
if (url.startsWith("//") && !url.startsWith("///")) {
|
|
497
502
|
const parsed = parseUrl(`${scheme}:${url}`);
|
package/package.json
CHANGED