url-sanitizer 5.2.0 → 5.2.1
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 +6 -6
- package/dist/url-sanitizer-wo-dompurify.min.js +1 -1
- package/dist/url-sanitizer-wo-dompurify.min.js.map +2 -2
- package/dist/url-sanitizer.min.js +1 -1
- package/dist/url-sanitizer.min.js.map +2 -2
- package/package.json +1 -1
- package/src/mjs/sanitize.js +10 -6
- package/src/mjs/scheme.js +2 -2
- package/src/mjs/text-chars.js +1 -1
package/package.json
CHANGED
package/src/mjs/sanitize.js
CHANGED
|
@@ -213,8 +213,8 @@ export class URLSanitizer extends URISchemes {
|
|
|
213
213
|
* @param {object} opt - User options.
|
|
214
214
|
* @returns {{ isValid: boolean|undefined, options: object, scheme: string|null }} Nomalized options, scheme, and isValid.
|
|
215
215
|
*/
|
|
216
|
-
#normalizeOptions(url, opt
|
|
217
|
-
if (!url ||
|
|
216
|
+
#normalizeOptions(url, opt) {
|
|
217
|
+
if (!isString(url) || url === '') {
|
|
218
218
|
return { isValid: false };
|
|
219
219
|
}
|
|
220
220
|
const options = {
|
|
@@ -258,7 +258,8 @@ export class URLSanitizer extends URISchemes {
|
|
|
258
258
|
sanitizedURL = this.#filter.sanitize(url, {
|
|
259
259
|
...this.#defaultOpts,
|
|
260
260
|
allow: ['data'],
|
|
261
|
-
allowRelative: true
|
|
261
|
+
allowRelative: true,
|
|
262
|
+
schemes: this.#allowedSchemes
|
|
262
263
|
});
|
|
263
264
|
if (!sanitizedURL) {
|
|
264
265
|
invalidReason =
|
|
@@ -366,7 +367,10 @@ export class URLSanitizer extends URISchemes {
|
|
|
366
367
|
* @returns {void}
|
|
367
368
|
*/
|
|
368
369
|
reset() {
|
|
369
|
-
this.#allowedSchemes
|
|
370
|
+
this.#allowedSchemes.clear();
|
|
371
|
+
for (const scheme of super.get()) {
|
|
372
|
+
this.#allowedSchemes.add(scheme);
|
|
373
|
+
}
|
|
370
374
|
}
|
|
371
375
|
|
|
372
376
|
/**
|
|
@@ -386,7 +390,7 @@ export class URLSanitizer extends URISchemes {
|
|
|
386
390
|
* @returns {Promise<string|null>} A promise resolving to the sanitized URL, or null.
|
|
387
391
|
*/
|
|
388
392
|
async sanitizeURL(url, opt) {
|
|
389
|
-
const { isValid, options, scheme } = this.#normalizeOptions(url, opt);
|
|
393
|
+
const { isValid, options, scheme } = this.#normalizeOptions(url, opt ?? {});
|
|
390
394
|
if (isValid === false) {
|
|
391
395
|
return null;
|
|
392
396
|
}
|
|
@@ -458,7 +462,7 @@ export class URLSanitizer extends URISchemes {
|
|
|
458
462
|
* @returns {string|null} The sanitized URL, or null if denied.
|
|
459
463
|
*/
|
|
460
464
|
sanitizeURLSync(url, opt) {
|
|
461
|
-
const { isValid, options, scheme } = this.#normalizeOptions(url, opt);
|
|
465
|
+
const { isValid, options, scheme } = this.#normalizeOptions(url, opt ?? {});
|
|
462
466
|
if (isValid === false) {
|
|
463
467
|
return null;
|
|
464
468
|
}
|
package/src/mjs/scheme.js
CHANGED
|
@@ -123,10 +123,10 @@ export class URISchemes {
|
|
|
123
123
|
* @returns {boolean} True if the parsed URL is valid and permitted.
|
|
124
124
|
*/
|
|
125
125
|
verifyScheme(scheme, schemes, allowCustom = false) {
|
|
126
|
-
|
|
126
|
+
const normalized = this.normalize(scheme, true);
|
|
127
|
+
if (!normalized) {
|
|
127
128
|
return false;
|
|
128
129
|
}
|
|
129
|
-
const normalized = this.normalize(scheme, true);
|
|
130
130
|
const targetSchemes = schemes || this.#schemes;
|
|
131
131
|
if (!normalized.includes('+')) {
|
|
132
132
|
if (REG_SCRIPT.test(normalized)) {
|
package/src/mjs/text-chars.js
CHANGED
|
@@ -49,7 +49,7 @@ export const WINDOWS1252_TO_UNICODE = new Map([
|
|
|
49
49
|
/**
|
|
50
50
|
* Generates hexadecimal escape strings for non-text codes.
|
|
51
51
|
* @private
|
|
52
|
-
* @returns {Map<number, string>} The map of non-text codes and
|
|
52
|
+
* @returns {Map<number, string>} The map of non-text codes and hexadecimal escape strings.
|
|
53
53
|
*/
|
|
54
54
|
const generateNonTextCharCodes = () => {
|
|
55
55
|
const charCodes = new Map();
|