url-sanitizer 2.3.0 → 2.3.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/package.json CHANGED
@@ -84,5 +84,5 @@
84
84
  "test:bdd": "http-server ./ -c-1 -o test/bdd/url-sanitizer.test.html",
85
85
  "tsc": "node scripts/index clean --dir=types -i && npx tsc"
86
86
  },
87
- "version": "2.3.0"
87
+ "version": "2.3.1"
88
88
  }
@@ -84,9 +84,15 @@ class URLSanitizer extends URISchemes {
84
84
  }
85
85
  this.#nest++;
86
86
  this.#recurse.add(dataUrl);
87
- const parsedDataUrl = this.sanitize(dataUrl, {
88
- allow: ['data']
89
- });
87
+ let parsedDataUrl;
88
+ try {
89
+ parsedDataUrl = this.sanitize(dataUrl, {
90
+ allow: ['data']
91
+ });
92
+ } finally {
93
+ this.#nest--;
94
+ this.#recurse.delete(dataUrl);
95
+ }
90
96
  const { index } = item;
91
97
  const [preDataUrl, postDataUrl] = [
92
98
  replacedData.substring(0, index),
@@ -149,7 +155,6 @@ class URLSanitizer extends URISchemes {
149
155
  */
150
156
  sanitize(url, opt) {
151
157
  if (this.#nest > HEX) {
152
- this.#nest = 0;
153
158
  throw new Error('Data URLs nested too deeply.');
154
159
  }
155
160
  const {
@@ -159,7 +164,7 @@ class URLSanitizer extends URISchemes {
159
164
  ['blob', false],
160
165
  ['data', false],
161
166
  ['file', false],
162
- ['javascrpt', false],
167
+ ['javascript', false],
163
168
  ['vbscript', false]
164
169
  ]);
165
170
  const tempScheme = new Set();
@@ -271,7 +276,6 @@ class URLSanitizer extends URISchemes {
271
276
  }
272
277
  if (bool) {
273
278
  const isDataUrl = isRelative ? false : schemeParts.includes('data');
274
- let finalize;
275
279
  let urlToSanitize = isRelative ? url : href;
276
280
  if (isDataUrl) {
277
281
  const [mediaType, ...dataParts] = pathname.split(',');
@@ -297,15 +301,7 @@ class URLSanitizer extends URISchemes {
297
301
  if (parsedData !== data || containsDataUrl) {
298
302
  if (containsDataUrl) {
299
303
  parsedData = this.replace(parsedData);
300
- } else if (this.#recurse.has(url)) {
301
- this.#recurse.delete(url);
302
- } else {
303
- finalize = true;
304
304
  }
305
- } else if (this.#recurse.has(url)) {
306
- this.#recurse.delete(url);
307
- } else {
308
- finalize = true;
309
305
  }
310
306
  if (!mediaType || REG_MIME_DOM.test(mediaType)) {
311
307
  parsedData = this.purify(parsedData);
@@ -318,8 +314,6 @@ class URLSanitizer extends URISchemes {
318
314
  } else {
319
315
  urlToSanitize = '';
320
316
  }
321
- } else {
322
- finalize = true;
323
317
  }
324
318
  if (!isDataUrl && REG_TAG_QUOT.test(urlToSanitize)) {
325
319
  const item = REG_TAG_QUOT.exec(urlToSanitize);
@@ -330,11 +324,6 @@ class URLSanitizer extends URISchemes {
330
324
  if (urlToSanitize) {
331
325
  sanitizedUrl =
332
326
  urlToSanitize.replace(/%26/g, escapeURLEncodedHTMLChars);
333
- if (finalize) {
334
- this.#nest = 0;
335
- }
336
- } else {
337
- this.#nest = 0;
338
327
  }
339
328
  }
340
329
  if (tempScheme.size) {