dompurify 2.4.4 → 3.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/dist/purify.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 2.4.4 | (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.4/LICENSE */
1
+ /*! @license DOMPurify 3.0.0 | (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.0/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.4';
438
+ DOMPurify.version = '3.0.0';
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,
@@ -873,11 +974,7 @@
873
974
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
874
975
  node.parentNode.removeChild(node);
875
976
  } catch (_) {
876
- try {
877
- node.outerHTML = emptyHTML;
878
- } catch (_) {
879
- node.remove();
880
- }
977
+ node.remove();
881
978
  }
882
979
  };
883
980
  /**
@@ -1056,14 +1153,6 @@
1056
1153
 
1057
1154
  return true;
1058
1155
  }
1059
- /* Check if tagname contains Unicode */
1060
-
1061
-
1062
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1063
- _forceRemove(currentNode);
1064
-
1065
- return true;
1066
- }
1067
1156
  /* Now let's check the element's type and name */
1068
1157
 
1069
1158
 
@@ -1082,14 +1171,6 @@
1082
1171
 
1083
1172
  return true;
1084
1173
  }
1085
- /* Mitigate a problem with templates inside select */
1086
-
1087
-
1088
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1089
- _forceRemove(currentNode);
1090
-
1091
- return true;
1092
- }
1093
1174
  /* Remove element if anything forbids its presence */
1094
1175
 
1095
1176
 
@@ -1127,6 +1208,8 @@
1127
1208
 
1128
1209
  return true;
1129
1210
  }
1211
+ /* Make sure that older browsers don't get noscript mXSS */
1212
+
1130
1213
 
1131
1214
  if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1132
1215
  _forceRemove(currentNode);
@@ -1403,7 +1486,6 @@
1403
1486
  var body;
1404
1487
  var importedNode;
1405
1488
  var currentNode;
1406
- var oldNode;
1407
1489
  var returnNode;
1408
1490
  /* Make sure we have a string to sanitize.
1409
1491
  DO NOT return early, as this will return the wrong type if
@@ -1429,20 +1511,10 @@
1429
1511
  }
1430
1512
  }
1431
1513
  }
1432
- /* Check we can run. Otherwise fall back or ignore */
1514
+ /* Return dirty HTML if DOMPurify cannot run */
1433
1515
 
1434
1516
 
1435
1517
  if (!DOMPurify.isSupported) {
1436
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1437
- if (typeof dirty === 'string') {
1438
- return window.toStaticHTML(dirty);
1439
- }
1440
-
1441
- if (_isNode(dirty)) {
1442
- return window.toStaticHTML(dirty.outerHTML);
1443
- }
1444
- }
1445
-
1446
1518
  return dirty;
1447
1519
  }
1448
1520
  /* Assign config vars */
@@ -1515,13 +1587,7 @@
1515
1587
 
1516
1588
 
1517
1589
  while (currentNode = nodeIterator.nextNode()) {
1518
- /* Fix IE's strange behavior with manipulated textNodes #89 */
1519
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
1520
- continue;
1521
- }
1522
1590
  /* Sanitize tags and elements */
1523
-
1524
-
1525
1591
  if (_sanitizeElements(currentNode)) {
1526
1592
  continue;
1527
1593
  }
@@ -1535,13 +1601,10 @@
1535
1601
 
1536
1602
 
1537
1603
  _sanitizeAttributes(currentNode);
1538
-
1539
- oldNode = currentNode;
1540
1604
  }
1541
-
1542
- oldNode = null;
1543
1605
  /* If we sanitized `dirty` in-place, return it. */
1544
1606
 
1607
+
1545
1608
  if (IN_PLACE) {
1546
1609
  return dirty;
1547
1610
  }