url-sanitizer 2.3.1 → 4.0.0

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.
@@ -0,0 +1,68 @@
1
+ /**
2
+ * text-chars.js
3
+ */
4
+
5
+ /* shared */
6
+ import textChars from '../lib/file/text-chars.json' with { type: 'json' };
7
+ import { HEX } from './constant.js';
8
+
9
+ /**
10
+ * A set of valid text character codes.
11
+ * @type {Set<number>}
12
+ */
13
+ export const TEXT_CHAR_CODES = new Set(textChars);
14
+
15
+ /**
16
+ * A mapping of Windows-1252 specific character codes to their corresponding Unicode code points.
17
+ * @type {Map<number, number>}
18
+ */
19
+ export const WINDOWS1252_TO_UNICODE = new Map([
20
+ [128, 0x20AC],
21
+ [130, 0x201A],
22
+ [131, 0x0192],
23
+ [132, 0x201E],
24
+ [133, 0x2026],
25
+ [134, 0x2020],
26
+ [135, 0x2021],
27
+ [136, 0x02C6],
28
+ [137, 0x2030],
29
+ [138, 0x0160],
30
+ [139, 0x2039],
31
+ [140, 0x0152],
32
+ [142, 0x017D],
33
+ [145, 0x2018],
34
+ [146, 0x2019],
35
+ [147, 0x201C],
36
+ [148, 0x201D],
37
+ [149, 0x2022],
38
+ [150, 0x2013],
39
+ [151, 0x2014],
40
+ [152, 0x02DC],
41
+ [153, 0x2122],
42
+ [154, 0x0161],
43
+ [155, 0x203A],
44
+ [156, 0x0153],
45
+ [158, 0x017E],
46
+ [159, 0x0178]
47
+ ]);
48
+
49
+ /**
50
+ * Generates control character codes in hex.
51
+ * @private
52
+ * @returns {Map<number, string>} Generated control char codes.
53
+ */
54
+ const generateCtrlCharCodes = () => {
55
+ const charCodes = new Map();
56
+ for (let i = 0; i < HEX * HEX; i++) {
57
+ if (!TEXT_CHAR_CODES.has(i) && !WINDOWS1252_TO_UNICODE.has(i)) {
58
+ charCodes.set(i, `\\x${i.toString(HEX).padStart(2, '0').toUpperCase()}`);
59
+ }
60
+ }
61
+ return charCodes;
62
+ };
63
+
64
+ /**
65
+ * A mapping of control character codes to their hexadecimal escape strings.
66
+ * @type {Map<number, string>}
67
+ */
68
+ export const CTRL_CHAR_CODES = generateCtrlCharCodes();
@@ -3,87 +3,191 @@
3
3
  */
4
4
 
5
5
  /* shared */
6
+ import uriSchemes from '../lib/iana/uri-schemes.json' with { type: 'json' };
6
7
  import { getType, isString } from './common.js';
7
8
  import { FileReader } from './file-reader.js';
8
- import { textChars, uriSchemes } from './lib-util.js';
9
9
 
10
+ /* constants */
11
+ import { DECI, HEX, MAX_BLOB_SIZE, MAX_NEST } from './constant.js';
10
12
  import {
11
- HEX, MAX_BLOB_SIZE, REG_B64, REG_NUM_REF, REG_SCHEME, REG_SCHEME_EXT,
12
- REG_SCRIPT, REG_URL_ENC
13
- } from './constant.js';
13
+ REG_HASH, REG_QUERY, REG_SCHEME_EXT, REG_SCRIPT, REG_URL_ENC
14
+ } from './regexp.js';
15
+ import {
16
+ CTRL_CHAR_CODES, TEXT_CHAR_CODES, WINDOWS1252_TO_UNICODE
17
+ } from './text-chars.js';
18
+ const [
19
+ ENC_AMP,
20
+ ENC_NUM,
21
+ ENC_LT,
22
+ ENC_GT,
23
+ ENC_QUOT,
24
+ ENC_APOS
25
+ ] = ['&', '#', '<', '>', '"', "'"].map(ch =>
26
+ `%${ch.charCodeAt(0).toString(HEX).toUpperCase()}`
27
+ );
28
+ const REG_BINARY = new RegExp(`[${[...CTRL_CHAR_CODES.values()].join('')}]`);
29
+ const REG_NUM_REF = /&#(x(?:00)?[\dA-F]{2}|0?\d{1,3});?/gi;
14
30
 
15
31
  /**
16
- * get URL encoded string
17
- * @param {string} str - string
18
- * @returns {string} - URL encoded string
32
+ * URI schemes
33
+ */
34
+ export class URISchemes {
35
+ /* private fields */
36
+ #schemes = new Set(uriSchemes);
37
+
38
+ /**
39
+ * Gets the list of registered URI schemes.
40
+ * @see {@link https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml}
41
+ * - Historical schemes are omitted.
42
+ * - The 'moz-extension' scheme is added by default.
43
+ * @returns {string[]} An array of registered schemes.
44
+ */
45
+ get() {
46
+ return [...this.#schemes];
47
+ }
48
+
49
+ /**
50
+ * Checks if the specified scheme is currently registered.
51
+ * @param {string} scheme - The target scheme.
52
+ * @returns {boolean} True if the scheme is registered.
53
+ */
54
+ has(scheme) {
55
+ return this.#schemes.has(scheme);
56
+ }
57
+
58
+ /**
59
+ * Verifies if the given URI is valid and its scheme is allowed.
60
+ * @param {string} uri - The URI string to verify.
61
+ * @param {Set<string>} [schemes] - The set of allowed schemes.
62
+ * @returns {boolean} True if the URI is syntactically valid and permitted.
63
+ */
64
+ verify(uri, schemes = this.#schemes) {
65
+ if (!isString(uri)) {
66
+ return false;
67
+ }
68
+ try {
69
+ const { protocol } = new URL(uri);
70
+ const scheme = protocol.replace(/:$/, '');
71
+ const parts = scheme.split('+');
72
+ const isScript = parts.some(s => REG_SCRIPT.test(s));
73
+ if (isScript) {
74
+ return false;
75
+ }
76
+ return REG_SCHEME_EXT.test(scheme) || parts.every(s => schemes.has(s));
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Gets the URL-encoded representation of a given string.
85
+ * @param {string} str - The target string.
86
+ * @returns {string} The completely URL-encoded string.
19
87
  */
20
88
  export const getURLEncodedString = str => {
21
89
  if (!isString(str)) {
22
90
  throw new TypeError(`Expected String but got ${getType(str)}.`);
23
91
  }
92
+ const encoder = new TextEncoder();
93
+ const bytes = encoder.encode(str);
24
94
  const chars = [];
25
- for (const ch of str) {
26
- chars.push(`%${ch.charCodeAt(0).toString(HEX).toUpperCase()}`);
95
+ for (const byte of bytes) {
96
+ chars.push(`%${byte.toString(HEX).padStart(2, '0').toUpperCase()}`);
27
97
  }
28
98
  return chars.join('');
29
99
  };
30
100
 
31
101
  /**
32
- * escape URL encoded HTML special chars
33
- * @param {string} ch - URL encoded (percent encoded) char
34
- * @returns {string} - escaped URL encoded HTML special char / URL encoded char
102
+ * Escapes URL-encoded HTML special characters.
103
+ * @param {string} ch - A URL-encoded (percent-encoded) character.
104
+ * @returns {string} The escaped HTML special character, or the given character.
35
105
  */
36
106
  export const escapeURLEncodedHTMLChars = ch => {
37
- if (isString(ch) && REG_URL_ENC.test(ch)) {
38
- ch = ch.toUpperCase();
39
- }
40
- const [amp, num, lt, gt, quot, apos] =
41
- ['&', '#', '<', '>', '"', "'"].map(getURLEncodedString);
42
- let escapedChar;
43
- if (ch === amp) {
44
- escapedChar = `${amp}amp;`;
45
- } else if (ch === lt) {
46
- escapedChar = `${amp}lt;`;
47
- } else if (ch === gt) {
48
- escapedChar = `${amp}gt;`;
49
- } else if (ch === quot) {
50
- escapedChar = `${amp}quot;`;
51
- } else if (ch === apos) {
52
- escapedChar = `${amp}${num}39;`;
53
- } else {
54
- escapedChar = ch;
107
+ let target = ch;
108
+ if (isString(target)) {
109
+ if (REG_URL_ENC.test(target)) {
110
+ target = target.toUpperCase();
111
+ }
112
+ switch (target) {
113
+ case ENC_AMP: {
114
+ return `${ENC_AMP}amp;`;
115
+ }
116
+ case ENC_LT: {
117
+ return `${ENC_AMP}lt;`;
118
+ }
119
+ case ENC_GT: {
120
+ return `${ENC_AMP}gt;`;
121
+ }
122
+ case ENC_QUOT: {
123
+ return `${ENC_AMP}quot;`;
124
+ }
125
+ case ENC_APOS: {
126
+ return `${ENC_AMP}${ENC_NUM}39;`;
127
+ }
128
+ default:
129
+ }
55
130
  }
56
- return escapedChar;
131
+ return target;
57
132
  };
58
133
 
59
134
  /**
60
- * parse base64 encoded data
61
- * @param {string} data - base64 encoded data
62
- * @returns {string} - parsed text data / base64 encoded data if binary
135
+ * Parses base64-encoded data.
136
+ * @param {string} data - The base64-encoded string.
137
+ * @returns {string} The parsed text, or the original base64 if binary.
63
138
  */
64
139
  export const parseBase64 = data => {
65
140
  if (!isString(data)) {
66
141
  throw new TypeError(`Expected String but got ${getType(data)}.`);
67
- } else if (!REG_B64.test(data)) {
142
+ }
143
+ const cleanData = data.replace(/\s/g, '');
144
+ let binStr;
145
+ try {
146
+ binStr = atob(cleanData);
147
+ } catch {
68
148
  throw new Error(`Invalid base64 data: ${data}`);
69
149
  }
70
- const bin = atob(data);
71
- const uint8arr = Uint8Array.from([...bin].map(c => c.charCodeAt(0)));
72
- const textCharCodes = new Set(textChars);
73
- let parsedData;
74
- if (uint8arr.every(c => textCharCodes.has(c))) {
75
- parsedData = bin.replace(/\s/g, getURLEncodedString);
76
- } else {
77
- parsedData = data;
150
+ const bytes = Uint8Array.from(binStr, c => c.charCodeAt(0));
151
+ try {
152
+ const decoder = new TextDecoder('utf-8', { fatal: true });
153
+ const text = decoder.decode(bytes);
154
+ if (REG_BINARY.test(text)) {
155
+ return cleanData;
156
+ }
157
+ return text;
158
+ } catch {
159
+ return cleanData;
78
160
  }
79
- return parsedData;
80
161
  };
81
162
 
82
163
  /**
83
- * parse URL encoded numeric character references in the range 0x00 to 0xFF
84
- * @param {string} str - string
85
- * @param {number} [nest] - nest level
86
- * @returns {string} - parsed string
164
+ * Replacer function for URL-encoded numeric character references.
165
+ * @param {string} match - The matched substring.
166
+ * @param {string} value - The captured numeric value.
167
+ * @returns {string} The resolved character or the original match.
168
+ */
169
+ export const replaceNumCharRef = (match, value) => {
170
+ const num = /x/i.test(value[0])
171
+ ? parseInt(value.substring(1), HEX)
172
+ : parseInt(value, DECI);
173
+ if (Number.isInteger(num)) {
174
+ if (TEXT_CHAR_CODES.has(num)) {
175
+ return String.fromCharCode(num);
176
+ } else if (WINDOWS1252_TO_UNICODE.has(num)) {
177
+ const codePoint = WINDOWS1252_TO_UNICODE.get(num);
178
+ return String.fromCodePoint(codePoint);
179
+ } else if (CTRL_CHAR_CODES.has(num)) {
180
+ return '';
181
+ }
182
+ }
183
+ return match;
184
+ };
185
+
186
+ /**
187
+ * Parses URL-encoded numeric character references in the range 0x00 to 0xFF.
188
+ * @param {string} str - The target string to parse.
189
+ * @param {number} [nest] - The current nesting depth for recursive parsing.
190
+ * @returns {string} The decoded and parsed string.
87
191
  */
88
192
  export const parseURLEncodedNumCharRef = (str, nest = 0) => {
89
193
  if (!isString(str)) {
@@ -91,56 +195,36 @@ export const parseURLEncodedNumCharRef = (str, nest = 0) => {
91
195
  }
92
196
  if (!Number.isInteger(nest)) {
93
197
  throw new TypeError(`Expected Number but got ${getType(nest)}.`);
94
- } else if (nest > HEX) {
95
- throw new Error('Character references nested too deeply.');
96
198
  }
97
199
  let res = decodeURIComponent(str);
98
- if (/&#/.test(res)) {
99
- const textCharCodes = new Set(textChars);
100
- const items = [...res.matchAll(REG_NUM_REF)].reverse();
101
- for (const item of items) {
102
- const [numCharRef, value] = item;
103
- let num;
104
- if (/^x[\dA-F]+/i.test(value)) {
105
- num = parseInt(`0${value}`, HEX);
106
- } else if (/^\d+/.test(value)) {
107
- num = parseInt(value);
108
- }
109
- if (Number.isInteger(num)) {
110
- const { index } = item;
111
- const [preNum, postNum] = [
112
- res.substring(0, index),
113
- res.substring(index + numCharRef.length)
114
- ];
115
- if (textCharCodes.has(num)) {
116
- res = `${preNum}${String.fromCharCode(num)}${postNum}`;
117
- if (/#x?$/.test(preNum) || /^#(?:x(?:00)?[2-7]|\d)/.test(postNum)) {
118
- res = parseURLEncodedNumCharRef(res, ++nest);
119
- }
120
- } else if (num < HEX * HEX) {
121
- res = `${preNum}${postNum}`;
122
- }
123
- }
200
+ while (/&#/.test(res)) {
201
+ if (nest > MAX_NEST) {
202
+ throw new Error('Character references nested too deeply.');
203
+ }
204
+ const previousRes = res;
205
+ res = res.replace(REG_NUM_REF, replaceNumCharRef);
206
+ if (res === previousRes) {
207
+ break;
124
208
  }
209
+ nest++;
125
210
  }
126
211
  return res;
127
212
  };
128
213
 
129
214
  /**
130
- * create data URL from blob
131
- * @param {object} blob - blob
132
- * @param {number} maxBlobSize - max blob size
133
- * @returns {Promise.<?string>} - data URL
215
+ * Creates a base64 data URL asynchronously from a given Blob.
216
+ * @param {Blob} blob - The target Blob object.
217
+ * @param {number} [maxBlobSize] - The maximum allowed blob size in bytes.
218
+ * @returns {Promise<string|null>} A promise resolving to the data URL, or null.
134
219
  */
135
220
  export const createDataURLFromBlob = (blob, maxBlobSize = MAX_BLOB_SIZE) =>
136
221
  new Promise((resolve, reject) => {
137
222
  if (!Number.isInteger(blob?.size)) {
138
223
  return resolve(null);
139
224
  } else if (Number.isInteger(maxBlobSize) && blob.size > maxBlobSize) {
140
- return reject(new DOMException(
141
- `Blob size (${blob.size} bytes) exceeds the maximum allowed size of ${maxBlobSize} bytes.`,
142
- 'NotReadableError'
143
- ));
225
+ const msg =
226
+ `Blob size (${blob.size} bytes) exceeds max (${maxBlobSize} bytes).`;
227
+ return reject(new DOMException(msg, 'NotReadableError'));
144
228
  }
145
229
  const reader = new FileReader();
146
230
  reader.addEventListener('error', () => reject(reader.error));
@@ -150,93 +234,13 @@ export const createDataURLFromBlob = (blob, maxBlobSize = MAX_BLOB_SIZE) =>
150
234
  });
151
235
 
152
236
  /**
153
- * URI schemes
237
+ * Safely removes a trailing empty hash and an empty query string from a URL.
238
+ * @param {string} url - The target URL string to be cleaned.
239
+ * @returns {string} The cleaned URL string or the original input.
154
240
  */
155
- export class URISchemes {
156
- /* private fields */
157
- #schemes;
158
-
159
- /**
160
- * construct
161
- */
162
- constructor() {
163
- this.#schemes = new Set(uriSchemes);
164
- }
165
-
166
- /**
167
- * get schemes
168
- * @see {@link https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml}
169
- * - Historical schemes omitted
170
- * - 'moz-extension' scheme added
171
- * @returns {Array.<string>} - array of schemes
172
- */
173
- get() {
174
- return [...this.#schemes];
175
- }
176
-
177
- /**
178
- * has scheme
179
- * @param {string} scheme - scheme
180
- * @returns {boolean} - result
181
- */
182
- has(scheme) {
183
- return this.#schemes.has(scheme);
184
- }
185
-
186
- /**
187
- * add scheme
188
- * NOTE: `javascript` and/or `vbscript` schemes can not be registered
189
- * @param {string} scheme - scheme
190
- * @returns {Array.<string>} - array of schemes
191
- */
192
- add(scheme) {
193
- if (!isString(scheme)) {
194
- throw new TypeError(`Expected String but got ${getType(scheme)}.`);
195
- } else if (REG_SCRIPT.test(scheme) || !REG_SCHEME.test(scheme)) {
196
- throw new Error(`Invalid scheme: ${scheme}`);
197
- }
198
- this.#schemes.add(scheme);
199
- return [...this.#schemes];
200
- }
201
-
202
- /**
203
- * remove scheme
204
- * @param {string} scheme - scheme
205
- * @returns {boolean} - result
206
- */
207
- remove(scheme) {
208
- return this.#schemes.delete(scheme);
209
- }
210
-
211
- /**
212
- * verify URI
213
- * @param {string} uri - URI
214
- * @returns {boolean} - result
215
- */
216
- verify(uri) {
217
- let res;
218
- if (isString(uri)) {
219
- try {
220
- const { protocol } = new URL(uri);
221
- const scheme = protocol.replace(/:$/, '');
222
- const schemeParts = scheme.split('+');
223
- res = (!REG_SCRIPT.test(scheme) && REG_SCHEME_EXT.test(scheme)) ||
224
- schemeParts.every(s => this.#schemes.has(s));
225
- } catch (e) {
226
- res = false;
227
- }
228
- }
229
- return !!res;
241
+ export const trimTrailingEmptyQueryAndHash = url => {
242
+ if (!isString(url)) {
243
+ return url;
230
244
  }
231
-
232
- /**
233
- * reset schemes
234
- * @returns {void}
235
- */
236
- reset() {
237
- this.#schemes.clear();
238
- for (const scheme of uriSchemes) {
239
- this.#schemes.add(scheme);
240
- }
241
- }
242
- }
245
+ return url.replace(REG_HASH, '').replace(REG_QUERY, '');
246
+ };
@@ -1,2 +1,2 @@
1
- export function getType(o: object): string;
2
- export function isString(o: object): boolean;
1
+ export function getType(o: unknown): string;
2
+ export function isString(o: unknown): boolean;
@@ -1,19 +1,7 @@
1
1
  export const CHUNK_SIZE: number;
2
- export const HEX: 16;
2
+ export const DECI: number;
3
+ export const HEX: number;
3
4
  export const MAX_BLOB_SIZE: number;
4
- export const TYPE_FROM: 8;
5
- export const TYPE_TO: -1;
6
- export const REG_B64: RegExp;
7
- export const REG_CHARSET: RegExp;
8
- export const REG_DATA_URL: RegExp;
9
- export const REG_DATA_URL_B64: RegExp;
10
- export const REG_DATA_URL_G: RegExp;
11
- export const REG_NUM_REF: RegExp;
12
- export const REG_MIME_DOM: RegExp;
13
- export const REG_MIME_TEXT: RegExp;
14
- export const REG_SCHEME: RegExp;
15
- export const REG_SCHEME_EXT: RegExp;
16
- export const REG_SCRIPT: RegExp;
17
- export const REG_SCRIPT_BLOB: RegExp;
18
- export const REG_TAG_QUOT: RegExp;
19
- export const REG_URL_ENC: RegExp;
5
+ export const MAX_NEST: number;
6
+ export const TYPE_FROM: number;
7
+ export const TYPE_TO: number;
@@ -1 +1 @@
1
- export const domPurify: import("dompurify").DOMPurify;
1
+ export const domPurify: typeof import("dompurify");
@@ -8,23 +8,23 @@ export class ProgressEvent extends Event {
8
8
  total?: number | undefined;
9
9
  });
10
10
  get lengthComputable(): boolean;
11
- get loaded(): number | undefined;
12
- get total(): number | undefined;
11
+ get loaded(): number;
12
+ get total(): number;
13
13
  #private;
14
14
  }
15
15
  export class FileReader extends EventTarget {
16
16
  EMPTY: number;
17
17
  LOADING: number;
18
18
  DONE: number;
19
- get error(): null;
19
+ get error(): Error | DOMException | null;
20
20
  get readyState(): number;
21
- get result(): null;
22
- _dispatchProgressEvent(type: string): boolean;
21
+ get result(): string | ArrayBuffer | null;
22
+ private _dispatchProgressEvent;
23
23
  abort(): void;
24
- _read(blob: object, format: string, encoding?: string): Promise<void>;
25
- readAsArrayBuffer(blob: object): Promise<void>;
26
- readAsBinaryString(blob: object): Promise<void>;
27
- readAsDataURL(blob: object): Promise<void>;
28
- readAsText(blob: object, encoding?: string): Promise<void>;
24
+ private _read;
25
+ readAsArrayBuffer(blob: Blob): Promise<void>;
26
+ readAsBinaryString(blob: Blob): Promise<void>;
27
+ readAsDataURL(blob: Blob): Promise<void>;
28
+ readAsText(blob: Blob, encoding?: string): Promise<void>;
29
29
  #private;
30
30
  }
@@ -0,0 +1,12 @@
1
+ export const REG_CHARSET: RegExp;
2
+ export const REG_HASH: RegExp;
3
+ export const REG_MIME_DOM: RegExp;
4
+ export const REG_MIME_TEXT: RegExp;
5
+ export const REG_QUERY: RegExp;
6
+ export const REG_SCHEME: RegExp;
7
+ export const REG_SCHEME_EXT: RegExp;
8
+ export const REG_SCRIPT: RegExp;
9
+ export const REG_SCRIPT_BLOB: RegExp;
10
+ export const REG_TAG_QUOT: RegExp;
11
+ export const REG_URL_ENC: RegExp;
12
+ export const REG_VERIFY_RELATIVE: RegExp;
@@ -3,25 +3,35 @@ export function sanitizeURL(url: string, opt?: {
3
3
  allow?: string[] | undefined;
4
4
  deny?: string[] | undefined;
5
5
  only?: string[] | undefined;
6
+ allowRelative?: boolean | undefined;
7
+ debug?: boolean | undefined;
8
+ revokeObjectURL?: boolean | undefined;
9
+ maxBlobSize?: number | undefined;
6
10
  }): Promise<string | null>;
7
11
  export function sanitizeURLSync(url: string, opt?: {
8
12
  allow?: string[] | undefined;
9
13
  deny?: string[] | undefined;
10
14
  only?: string[] | undefined;
15
+ allowRelative?: boolean | undefined;
16
+ debug?: boolean | undefined;
17
+ revokeObjectURL?: boolean | undefined;
11
18
  }): string | null;
12
- export function parseURL(url: string): Promise<ParsedURL>;
13
- export function parseURLSync(url: string): ParsedURL;
19
+ export function inspectURL(url: string): Promise<InspectedURLResult>;
20
+ export function parseURL(url: string): Promise<InspectedURLResult>;
21
+ export function inspectURLSync(url: string): InspectedURLResult;
22
+ export function parseURLSync(url: string): InspectedURLResult;
14
23
  export function isURI(uri: string): Promise<boolean>;
15
24
  export function isURISync(uri: string): boolean;
16
25
  export default urlSanitizer;
17
- export type ParsedURL = {
26
+ export type InspectedDataURL = {
27
+ mime: string;
28
+ base64: boolean;
29
+ data: string;
30
+ };
31
+ export type InspectedURLResult = {
18
32
  input: string;
19
33
  valid: boolean;
20
- data?: {
21
- mime?: string | undefined;
22
- base64?: boolean | undefined;
23
- data?: string | undefined;
24
- } | undefined;
34
+ data?: InspectedDataURL | null | undefined;
25
35
  href?: string | undefined;
26
36
  origin?: string | undefined;
27
37
  protocol?: string | undefined;
@@ -35,20 +45,21 @@ export type ParsedURL = {
35
45
  hash?: string | undefined;
36
46
  };
37
47
  export class URLSanitizer extends URISchemes {
38
- replace(data: string): string;
39
- purify(dom: string): string;
48
+ static #currentCtx: null;
49
+ static #currentInstance: URLSanitizer | null;
50
+ private static #uponSanitizeAttribute;
40
51
  sanitize(url: string, opt?: {
41
52
  allow?: string[] | undefined;
42
53
  deny?: string[] | undefined;
43
54
  only?: string[] | undefined;
44
55
  allowRelative?: boolean | undefined;
45
56
  debug?: boolean | undefined;
57
+ maxBlobSize?: number | undefined;
46
58
  }): string | null;
47
- parse(url: string, opt?: {
48
- allow?: string[] | undefined;
49
- deny?: string[] | undefined;
50
- only?: string[] | undefined;
51
- }): ParsedURL;
59
+ inspect(url: string, opt?: object): InspectedURLResult;
60
+ add(scheme: string): string[];
61
+ remove(scheme: string): boolean;
62
+ reset(): void;
52
63
  #private;
53
64
  }
54
65
  declare const urlSanitizer: URLSanitizer;
@@ -0,0 +1,3 @@
1
+ export const TEXT_CHAR_CODES: Set<number>;
2
+ export const WINDOWS1252_TO_UNICODE: Map<number, number>;
3
+ export const CTRL_CHAR_CODES: Map<number, string>;
@@ -1,14 +1,13 @@
1
- export function getURLEncodedString(str: string): string;
2
- export function escapeURLEncodedHTMLChars(ch: string): string;
3
- export function parseBase64(data: string): string;
4
- export function parseURLEncodedNumCharRef(str: string, nest?: number): string;
5
- export function createDataURLFromBlob(blob: object, maxBlobSize?: number): Promise<string | null>;
6
1
  export class URISchemes {
7
- get(): Array<string>;
2
+ get(): string[];
8
3
  has(scheme: string): boolean;
9
- add(scheme: string): Array<string>;
10
- remove(scheme: string): boolean;
11
- verify(uri: string): boolean;
12
- reset(): void;
4
+ verify(uri: string, schemes?: Set<string>): boolean;
13
5
  #private;
14
6
  }
7
+ export function getURLEncodedString(str: string): string;
8
+ export function escapeURLEncodedHTMLChars(ch: string): string;
9
+ export function parseBase64(data: string): string;
10
+ export function replaceNumCharRef(match: string, value: string): string;
11
+ export function parseURLEncodedNumCharRef(str: string, nest?: number): string;
12
+ export function createDataURLFromBlob(blob: Blob, maxBlobSize?: number): Promise<string | null>;
13
+ export function trimTrailingEmptyQueryAndHash(url: string): string;