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.es.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 _typeof(obj) {
4
4
  "@babel/helpers - typeof";
@@ -49,6 +49,10 @@ function _construct(Parent, args, Class) {
49
49
  return _construct.apply(null, arguments);
50
50
  }
51
51
 
52
+ function _slicedToArray(arr, i) {
53
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
54
+ }
55
+
52
56
  function _toConsumableArray(arr) {
53
57
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
54
58
  }
@@ -57,10 +61,44 @@ function _arrayWithoutHoles(arr) {
57
61
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
58
62
  }
59
63
 
64
+ function _arrayWithHoles(arr) {
65
+ if (Array.isArray(arr)) return arr;
66
+ }
67
+
60
68
  function _iterableToArray(iter) {
61
69
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
62
70
  }
63
71
 
72
+ function _iterableToArrayLimit(arr, i) {
73
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
74
+
75
+ if (_i == null) return;
76
+ var _arr = [];
77
+ var _n = true;
78
+ var _d = false;
79
+
80
+ var _s, _e;
81
+
82
+ try {
83
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
84
+ _arr.push(_s.value);
85
+
86
+ if (i && _arr.length === i) break;
87
+ }
88
+ } catch (err) {
89
+ _d = true;
90
+ _e = err;
91
+ } finally {
92
+ try {
93
+ if (!_n && _i["return"] != null) _i["return"]();
94
+ } finally {
95
+ if (_d) throw _e;
96
+ }
97
+ }
98
+
99
+ return _arr;
100
+ }
101
+
64
102
  function _unsupportedIterableToArray(o, minLen) {
65
103
  if (!o) return;
66
104
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -82,7 +120,68 @@ function _nonIterableSpread() {
82
120
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83
121
  }
84
122
 
85
- var hasOwnProperty = Object.hasOwnProperty,
123
+ function _nonIterableRest() {
124
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
125
+ }
126
+
127
+ function _createForOfIteratorHelper(o, allowArrayLike) {
128
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
129
+
130
+ if (!it) {
131
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
132
+ if (it) o = it;
133
+ var i = 0;
134
+
135
+ var F = function () {};
136
+
137
+ return {
138
+ s: F,
139
+ n: function () {
140
+ if (i >= o.length) return {
141
+ done: true
142
+ };
143
+ return {
144
+ done: false,
145
+ value: o[i++]
146
+ };
147
+ },
148
+ e: function (e) {
149
+ throw e;
150
+ },
151
+ f: F
152
+ };
153
+ }
154
+
155
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
156
+ }
157
+
158
+ var normalCompletion = true,
159
+ didErr = false,
160
+ err;
161
+ return {
162
+ s: function () {
163
+ it = it.call(o);
164
+ },
165
+ n: function () {
166
+ var step = it.next();
167
+ normalCompletion = step.done;
168
+ return step;
169
+ },
170
+ e: function (e) {
171
+ didErr = true;
172
+ err = e;
173
+ },
174
+ f: function () {
175
+ try {
176
+ if (!normalCompletion && it.return != null) it.return();
177
+ } finally {
178
+ if (didErr) throw err;
179
+ }
180
+ }
181
+ };
182
+ }
183
+
184
+ var entries = Object.entries,
86
185
  setPrototypeOf = Object.setPrototypeOf,
87
186
  isFrozen = Object.isFrozen,
88
187
  getPrototypeOf = Object.getPrototypeOf,
@@ -187,20 +286,28 @@ function addToSet(set, array, transformCaseFunc) {
187
286
 
188
287
  function clone(object) {
189
288
  var newObject = create(null);
190
- var property;
191
289
 
192
- for (property in object) {
193
- if (apply(hasOwnProperty, object, [property]) === true) {
194
- newObject[property] = object[property];
290
+ var _iterator = _createForOfIteratorHelper(entries(object)),
291
+ _step;
292
+
293
+ try {
294
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
295
+ var _step$value = _slicedToArray(_step.value, 2),
296
+ property = _step$value[0],
297
+ value = _step$value[1];
298
+
299
+ newObject[property] = value;
195
300
  }
301
+ } catch (err) {
302
+ _iterator.e(err);
303
+ } finally {
304
+ _iterator.f();
196
305
  }
197
306
 
198
307
  return newObject;
199
308
  }
200
- /* IE10 doesn't support __lookupGetter__ so lets'
201
- * simulate it. It also automatically checks
202
- * if the prop is function or getter and behaves
203
- * accordingly. */
309
+ /* This method automatically checks if the prop is function
310
+ * or getter and behaves accordingly. */
204
311
 
205
312
  function lookupGetter(object, prop) {
206
313
  while (object !== null) {
@@ -322,7 +429,7 @@ function createDOMPurify() {
322
429
  */
323
430
 
324
431
 
325
- DOMPurify.version = '2.4.4';
432
+ DOMPurify.version = '3.0.0';
326
433
  /**
327
434
  * Array of elements that DOMPurify removed during sanitation.
328
435
  * Empty if nothing was removed.
@@ -377,18 +484,12 @@ function createDOMPurify() {
377
484
  createDocumentFragment = _document.createDocumentFragment,
378
485
  getElementsByTagName = _document.getElementsByTagName;
379
486
  var importNode = originalDocument.importNode;
380
- var documentMode = {};
381
-
382
- try {
383
- documentMode = clone(document).documentMode ? document.documentMode : {};
384
- } catch (_) {}
385
-
386
487
  var hooks = {};
387
488
  /**
388
489
  * Expose whether this browser supports running the full DOMPurify.
389
490
  */
390
491
 
391
- DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
492
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined';
392
493
  var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
393
494
  ERB_EXPR$1 = ERB_EXPR,
394
495
  TMPLIT_EXPR$1 = TMPLIT_EXPR,
@@ -867,11 +968,7 @@ function createDOMPurify() {
867
968
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
868
969
  node.parentNode.removeChild(node);
869
970
  } catch (_) {
870
- try {
871
- node.outerHTML = emptyHTML;
872
- } catch (_) {
873
- node.remove();
874
- }
971
+ node.remove();
875
972
  }
876
973
  };
877
974
  /**
@@ -1050,14 +1147,6 @@ function createDOMPurify() {
1050
1147
 
1051
1148
  return true;
1052
1149
  }
1053
- /* Check if tagname contains Unicode */
1054
-
1055
-
1056
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1057
- _forceRemove(currentNode);
1058
-
1059
- return true;
1060
- }
1061
1150
  /* Now let's check the element's type and name */
1062
1151
 
1063
1152
 
@@ -1076,14 +1165,6 @@ function createDOMPurify() {
1076
1165
 
1077
1166
  return true;
1078
1167
  }
1079
- /* Mitigate a problem with templates inside select */
1080
-
1081
-
1082
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1083
- _forceRemove(currentNode);
1084
-
1085
- return true;
1086
- }
1087
1168
  /* Remove element if anything forbids its presence */
1088
1169
 
1089
1170
 
@@ -1121,6 +1202,8 @@ function createDOMPurify() {
1121
1202
 
1122
1203
  return true;
1123
1204
  }
1205
+ /* Make sure that older browsers don't get noscript mXSS */
1206
+
1124
1207
 
1125
1208
  if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1126
1209
  _forceRemove(currentNode);
@@ -1397,7 +1480,6 @@ function createDOMPurify() {
1397
1480
  var body;
1398
1481
  var importedNode;
1399
1482
  var currentNode;
1400
- var oldNode;
1401
1483
  var returnNode;
1402
1484
  /* Make sure we have a string to sanitize.
1403
1485
  DO NOT return early, as this will return the wrong type if
@@ -1423,20 +1505,10 @@ function createDOMPurify() {
1423
1505
  }
1424
1506
  }
1425
1507
  }
1426
- /* Check we can run. Otherwise fall back or ignore */
1508
+ /* Return dirty HTML if DOMPurify cannot run */
1427
1509
 
1428
1510
 
1429
1511
  if (!DOMPurify.isSupported) {
1430
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1431
- if (typeof dirty === 'string') {
1432
- return window.toStaticHTML(dirty);
1433
- }
1434
-
1435
- if (_isNode(dirty)) {
1436
- return window.toStaticHTML(dirty.outerHTML);
1437
- }
1438
- }
1439
-
1440
1512
  return dirty;
1441
1513
  }
1442
1514
  /* Assign config vars */
@@ -1509,13 +1581,7 @@ function createDOMPurify() {
1509
1581
 
1510
1582
 
1511
1583
  while (currentNode = nodeIterator.nextNode()) {
1512
- /* Fix IE's strange behavior with manipulated textNodes #89 */
1513
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
1514
- continue;
1515
- }
1516
1584
  /* Sanitize tags and elements */
1517
-
1518
-
1519
1585
  if (_sanitizeElements(currentNode)) {
1520
1586
  continue;
1521
1587
  }
@@ -1529,13 +1595,10 @@ function createDOMPurify() {
1529
1595
 
1530
1596
 
1531
1597
  _sanitizeAttributes(currentNode);
1532
-
1533
- oldNode = currentNode;
1534
1598
  }
1535
-
1536
- oldNode = null;
1537
1599
  /* If we sanitized `dirty` in-place, return it. */
1538
1600
 
1601
+
1539
1602
  if (IN_PLACE) {
1540
1603
  return dirty;
1541
1604
  }