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.
- package/README.md +166 -74
- package/dist/url-sanitizer-wo-dompurify.min.js +1 -1
- package/dist/url-sanitizer-wo-dompurify.min.js.map +4 -4
- package/dist/url-sanitizer.min.js +4 -4
- package/dist/url-sanitizer.min.js.map +4 -4
- package/package.json +16 -14
- package/src/lib/file/text-chars.json +1 -1
- package/src/mjs/common.js +7 -6
- package/src/mjs/constant.js +39 -19
- package/src/mjs/dompurify.js +6 -0
- package/src/mjs/file-reader.js +125 -68
- package/src/mjs/regexp.js +79 -0
- package/src/mjs/sanitizer.js +416 -249
- package/src/mjs/text-chars.js +68 -0
- package/src/mjs/uri-util.js +176 -172
- package/types/mjs/common.d.ts +2 -2
- package/types/mjs/constant.d.ts +5 -17
- package/types/mjs/dompurify.d.ts +1 -1
- package/types/mjs/file-reader.d.ts +10 -10
- package/types/mjs/regexp.d.ts +12 -0
- package/types/mjs/sanitizer.d.ts +26 -15
- package/types/mjs/text-chars.d.ts +3 -0
- package/types/mjs/uri-util.d.ts +9 -10
- package/src/mjs/lib-util.js +0 -37
- package/types/mjs/lib-util.d.ts +0 -3
|
@@ -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();
|
package/src/mjs/uri-util.js
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
26
|
-
chars.push(`%${
|
|
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
|
-
*
|
|
33
|
-
* @param {string} ch - URL
|
|
34
|
-
* @returns {string}
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
131
|
+
return target;
|
|
57
132
|
};
|
|
58
133
|
|
|
59
134
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {string} data - base64
|
|
62
|
-
* @returns {string}
|
|
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
|
-
}
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
*
|
|
84
|
-
* @param {string}
|
|
85
|
-
* @param {
|
|
86
|
-
* @returns {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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
*
|
|
131
|
-
* @param {
|
|
132
|
-
* @param {number} maxBlobSize -
|
|
133
|
-
* @returns {Promise
|
|
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
|
-
|
|
141
|
-
`Blob size (${blob.size} bytes) exceeds
|
|
142
|
-
|
|
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
|
-
*
|
|
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
|
|
156
|
-
|
|
157
|
-
|
|
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
|
+
};
|
package/types/mjs/common.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function getType(o:
|
|
2
|
-
export function isString(o:
|
|
1
|
+
export function getType(o: unknown): string;
|
|
2
|
+
export function isString(o: unknown): boolean;
|
package/types/mjs/constant.d.ts
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
export const CHUNK_SIZE: number;
|
|
2
|
-
export const
|
|
2
|
+
export const DECI: number;
|
|
3
|
+
export const HEX: number;
|
|
3
4
|
export const MAX_BLOB_SIZE: number;
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
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;
|
package/types/mjs/dompurify.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const domPurify: import("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
|
|
12
|
-
get total(): number
|
|
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
|
|
21
|
+
get result(): string | ArrayBuffer | null;
|
|
22
|
+
private _dispatchProgressEvent;
|
|
23
23
|
abort(): void;
|
|
24
|
-
_read
|
|
25
|
-
readAsArrayBuffer(blob:
|
|
26
|
-
readAsBinaryString(blob:
|
|
27
|
-
readAsDataURL(blob:
|
|
28
|
-
readAsText(blob:
|
|
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;
|
package/types/mjs/sanitizer.d.ts
CHANGED
|
@@ -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
|
|
13
|
-
export function
|
|
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
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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;
|
package/types/mjs/uri-util.d.ts
CHANGED
|
@@ -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():
|
|
2
|
+
get(): string[];
|
|
8
3
|
has(scheme: string): boolean;
|
|
9
|
-
|
|
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;
|