url-sanitizer 5.3.2 → 5.3.3
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/url-sanitizer-wo-dompurify.min.js +1 -1
- package/dist/url-sanitizer-wo-dompurify.min.js.map +3 -3
- package/dist/url-sanitizer.min.js +3 -3
- package/dist/url-sanitizer.min.js.map +3 -3
- package/package.json +1 -1
- package/src/index.js +3 -1
- package/src/mjs/sanitize.js +4 -8
- package/types/index.d.ts +1 -1
- package/types/mjs/filter.d.ts +1 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -84,9 +84,11 @@ export const sanitizeURLSync = (url, opt) =>
|
|
|
84
84
|
* Sanitizes the given URL and returns its parsed components.
|
|
85
85
|
* NOTE: Blob URLs are not revoked after inspection.
|
|
86
86
|
* @param {string} url - The URL string to inspect.
|
|
87
|
+
* @param {SanitizeOptions} [opt] - The sanitization options.
|
|
87
88
|
* @returns {Promise<InspectedURLResult>} A promise resolving to the inspected URL result.
|
|
88
89
|
*/
|
|
89
|
-
export const inspectURL = async url
|
|
90
|
+
export const inspectURL = async (url, opt = {}) =>
|
|
91
|
+
sanitizer.inspectURL(url, opt);
|
|
90
92
|
|
|
91
93
|
/**
|
|
92
94
|
* Checks if the given string is a valid URI and is registered.
|
package/src/mjs/sanitize.js
CHANGED
|
@@ -118,9 +118,10 @@ export class URLSanitizer extends URISchemes {
|
|
|
118
118
|
* Inspects, parses, and sanitizes the given URL.
|
|
119
119
|
* @private
|
|
120
120
|
* @param {string} url - The URL string to parse.
|
|
121
|
+
* @param {InternalSanitizeOptions} options - Sanitization options.
|
|
121
122
|
* @returns {InspectedURLResult} The result of an inspected URL.
|
|
122
123
|
*/
|
|
123
|
-
#inspect(url) {
|
|
124
|
+
#inspect(url, options) {
|
|
124
125
|
const inspectedURL = {
|
|
125
126
|
input: url,
|
|
126
127
|
href: null,
|
|
@@ -137,12 +138,7 @@ export class URLSanitizer extends URISchemes {
|
|
|
137
138
|
let sanitizedURL;
|
|
138
139
|
let invalidReason = null;
|
|
139
140
|
try {
|
|
140
|
-
sanitizedURL = this.#filter.sanitize(url,
|
|
141
|
-
...this.#defaultOpts,
|
|
142
|
-
allow: ['data'],
|
|
143
|
-
allowRelative: true,
|
|
144
|
-
schemes: this.#allowedSchemes
|
|
145
|
-
});
|
|
141
|
+
sanitizedURL = this.#filter.sanitize(url, options);
|
|
146
142
|
if (!sanitizedURL) {
|
|
147
143
|
invalidReason =
|
|
148
144
|
'Sanitization failed (blocked by allowed schemes or rules).';
|
|
@@ -389,7 +385,7 @@ export class URLSanitizer extends URISchemes {
|
|
|
389
385
|
* @param {SanitizeOptions} [opt] - The sanitization options.
|
|
390
386
|
* @returns {Promise<InspectedURLResult>} A promise resolving to the inspected URL result.
|
|
391
387
|
*/
|
|
392
|
-
async inspectURL(url, opt) {
|
|
388
|
+
async inspectURL(url, opt = {}) {
|
|
393
389
|
const { options, scheme } = this.#normalizeOptions(url, opt);
|
|
394
390
|
if (scheme === 'blob') {
|
|
395
391
|
return this.#inspectBlob(url, options);
|
package/types/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export { URLSanitizer };
|
|
|
44
44
|
declare const sanitizer: URLSanitizer;
|
|
45
45
|
export declare const sanitizeURL: (url: string, opt?: SanitizeOptions) => Promise<string | null>;
|
|
46
46
|
export declare const sanitizeURLSync: (url: string, opt?: SanitizeOptions) => string | null;
|
|
47
|
-
export declare const inspectURL: (url: string) => Promise<InspectedURLResult>;
|
|
47
|
+
export declare const inspectURL: (url: string, opt?: SanitizeOptions) => Promise<InspectedURLResult>;
|
|
48
48
|
export declare const isValidURI: (uri: string) => boolean;
|
|
49
49
|
export declare const isURISync: (uri: string) => boolean;
|
|
50
50
|
export default sanitizer;
|
package/types/mjs/filter.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare class SanitizeContext {
|
|
|
12
12
|
schemeMap: Map<string, boolean>;
|
|
13
13
|
allowRelative: boolean | undefined;
|
|
14
14
|
debug: boolean | undefined;
|
|
15
|
+
schemes: Set<string> | undefined;
|
|
15
16
|
constructor(domPurifyInstance: DOMPurify, opt?: InternalSanitizeOptions);
|
|
16
17
|
private #compileRules;
|
|
17
18
|
private #registerScheme;
|