dompurify 2.4.5 → 3.0.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/dist/purify.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 2.4.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.5/LICENSE */
1
+ /*! @license DOMPurify 3.0.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.1/LICENSE */
2
2
 
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -55,6 +55,10 @@
55
55
  return _construct.apply(null, arguments);
56
56
  }
57
57
 
58
+ function _slicedToArray(arr, i) {
59
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
60
+ }
61
+
58
62
  function _toConsumableArray(arr) {
59
63
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
60
64
  }
@@ -63,10 +67,44 @@
63
67
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
64
68
  }
65
69
 
70
+ function _arrayWithHoles(arr) {
71
+ if (Array.isArray(arr)) return arr;
72
+ }
73
+
66
74
  function _iterableToArray(iter) {
67
75
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
68
76
  }
69
77
 
78
+ function _iterableToArrayLimit(arr, i) {
79
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
80
+
81
+ if (_i == null) return;
82
+ var _arr = [];
83
+ var _n = true;
84
+ var _d = false;
85
+
86
+ var _s, _e;
87
+
88
+ try {
89
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
90
+ _arr.push(_s.value);
91
+
92
+ if (i && _arr.length === i) break;
93
+ }
94
+ } catch (err) {
95
+ _d = true;
96
+ _e = err;
97
+ } finally {
98
+ try {
99
+ if (!_n && _i["return"] != null) _i["return"]();
100
+ } finally {
101
+ if (_d) throw _e;
102
+ }
103
+ }
104
+
105
+ return _arr;
106
+ }
107
+
70
108
  function _unsupportedIterableToArray(o, minLen) {
71
109
  if (!o) return;
72
110
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -88,7 +126,68 @@
88
126
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89
127
  }
90
128
 
91
- var hasOwnProperty = Object.hasOwnProperty,
129
+ function _nonIterableRest() {
130
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
131
+ }
132
+
133
+ function _createForOfIteratorHelper(o, allowArrayLike) {
134
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
135
+
136
+ if (!it) {
137
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
138
+ if (it) o = it;
139
+ var i = 0;
140
+
141
+ var F = function () {};
142
+
143
+ return {
144
+ s: F,
145
+ n: function () {
146
+ if (i >= o.length) return {
147
+ done: true
148
+ };
149
+ return {
150
+ done: false,
151
+ value: o[i++]
152
+ };
153
+ },
154
+ e: function (e) {
155
+ throw e;
156
+ },
157
+ f: F
158
+ };
159
+ }
160
+
161
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
162
+ }
163
+
164
+ var normalCompletion = true,
165
+ didErr = false,
166
+ err;
167
+ return {
168
+ s: function () {
169
+ it = it.call(o);
170
+ },
171
+ n: function () {
172
+ var step = it.next();
173
+ normalCompletion = step.done;
174
+ return step;
175
+ },
176
+ e: function (e) {
177
+ didErr = true;
178
+ err = e;
179
+ },
180
+ f: function () {
181
+ try {
182
+ if (!normalCompletion && it.return != null) it.return();
183
+ } finally {
184
+ if (didErr) throw err;
185
+ }
186
+ }
187
+ };
188
+ }
189
+
190
+ var entries = Object.entries,
92
191
  setPrototypeOf = Object.setPrototypeOf,
93
192
  isFrozen = Object.isFrozen,
94
193
  getPrototypeOf = Object.getPrototypeOf,
@@ -193,20 +292,28 @@
193
292
 
194
293
  function clone(object) {
195
294
  var newObject = create(null);
196
- var property;
197
295
 
198
- for (property in object) {
199
- if (apply(hasOwnProperty, object, [property]) === true) {
200
- newObject[property] = object[property];
296
+ var _iterator = _createForOfIteratorHelper(entries(object)),
297
+ _step;
298
+
299
+ try {
300
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
301
+ var _step$value = _slicedToArray(_step.value, 2),
302
+ property = _step$value[0],
303
+ value = _step$value[1];
304
+
305
+ newObject[property] = value;
201
306
  }
307
+ } catch (err) {
308
+ _iterator.e(err);
309
+ } finally {
310
+ _iterator.f();
202
311
  }
203
312
 
204
313
  return newObject;
205
314
  }
206
- /* IE10 doesn't support __lookupGetter__ so lets'
207
- * simulate it. It also automatically checks
208
- * if the prop is function or getter and behaves
209
- * accordingly. */
315
+ /* This method automatically checks if the prop is function
316
+ * or getter and behaves accordingly. */
210
317
 
211
318
  function lookupGetter(object, prop) {
212
319
  while (object !== null) {
@@ -328,7 +435,7 @@
328
435
  */
329
436
 
330
437
 
331
- DOMPurify.version = '2.4.5';
438
+ DOMPurify.version = '3.0.1';
332
439
  /**
333
440
  * Array of elements that DOMPurify removed during sanitation.
334
441
  * Empty if nothing was removed.
@@ -383,18 +490,12 @@
383
490
  createDocumentFragment = _document.createDocumentFragment,
384
491
  getElementsByTagName = _document.getElementsByTagName;
385
492
  var importNode = originalDocument.importNode;
386
- var documentMode = {};
387
-
388
- try {
389
- documentMode = clone(document).documentMode ? document.documentMode : {};
390
- } catch (_) {}
391
-
392
493
  var hooks = {};
393
494
  /**
394
495
  * Expose whether this browser supports running the full DOMPurify.
395
496
  */
396
497
 
397
- DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
498
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
398
499
  var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
399
500
  ERB_EXPR$1 = ERB_EXPR,
400
501
  TMPLIT_EXPR$1 = TMPLIT_EXPR,
@@ -874,11 +975,7 @@
874
975
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
875
976
  node.parentNode.removeChild(node);
876
977
  } catch (_) {
877
- try {
878
- node.outerHTML = emptyHTML;
879
- } catch (_) {
880
- node.remove();
881
- }
978
+ node.remove();
882
979
  }
883
980
  };
884
981
  /**
@@ -1057,14 +1154,6 @@
1057
1154
 
1058
1155
  return true;
1059
1156
  }
1060
- /* Check if tagname contains Unicode */
1061
-
1062
-
1063
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1064
- _forceRemove(currentNode);
1065
-
1066
- return true;
1067
- }
1068
1157
  /* Now let's check the element's type and name */
1069
1158
 
1070
1159
 
@@ -1083,14 +1172,6 @@
1083
1172
 
1084
1173
  return true;
1085
1174
  }
1086
- /* Mitigate a problem with templates inside select */
1087
-
1088
-
1089
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1090
- _forceRemove(currentNode);
1091
-
1092
- return true;
1093
- }
1094
1175
  /* Remove element if anything forbids its presence */
1095
1176
 
1096
1177
 
@@ -1128,6 +1209,8 @@
1128
1209
 
1129
1210
  return true;
1130
1211
  }
1212
+ /* Make sure that older browsers don't get noscript mXSS */
1213
+
1131
1214
 
1132
1215
  if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1133
1216
  _forceRemove(currentNode);
@@ -1404,7 +1487,6 @@
1404
1487
  var body;
1405
1488
  var importedNode;
1406
1489
  var currentNode;
1407
- var oldNode;
1408
1490
  var returnNode;
1409
1491
  /* Make sure we have a string to sanitize.
1410
1492
  DO NOT return early, as this will return the wrong type if
@@ -1430,20 +1512,10 @@
1430
1512
  }
1431
1513
  }
1432
1514
  }
1433
- /* Check we can run. Otherwise fall back or ignore */
1515
+ /* Return dirty HTML if DOMPurify cannot run */
1434
1516
 
1435
1517
 
1436
1518
  if (!DOMPurify.isSupported) {
1437
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1438
- if (typeof dirty === 'string') {
1439
- return window.toStaticHTML(dirty);
1440
- }
1441
-
1442
- if (_isNode(dirty)) {
1443
- return window.toStaticHTML(dirty.outerHTML);
1444
- }
1445
- }
1446
-
1447
1519
  return dirty;
1448
1520
  }
1449
1521
  /* Assign config vars */
@@ -1516,13 +1588,7 @@
1516
1588
 
1517
1589
 
1518
1590
  while (currentNode = nodeIterator.nextNode()) {
1519
- /* Fix IE's strange behavior with manipulated textNodes #89 */
1520
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
1521
- continue;
1522
- }
1523
1591
  /* Sanitize tags and elements */
1524
-
1525
-
1526
1592
  if (_sanitizeElements(currentNode)) {
1527
1593
  continue;
1528
1594
  }
@@ -1536,13 +1602,10 @@
1536
1602
 
1537
1603
 
1538
1604
  _sanitizeAttributes(currentNode);
1539
-
1540
- oldNode = currentNode;
1541
1605
  }
1542
-
1543
- oldNode = null;
1544
1606
  /* If we sanitized `dirty` in-place, return it. */
1545
1607
 
1608
+
1546
1609
  if (IN_PLACE) {
1547
1610
  return dirty;
1548
1611
  }