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.es.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 _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.5';
432
+ DOMPurify.version = '3.0.1';
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,
@@ -868,11 +969,7 @@ function createDOMPurify() {
868
969
  // eslint-disable-next-line unicorn/prefer-dom-node-remove
869
970
  node.parentNode.removeChild(node);
870
971
  } catch (_) {
871
- try {
872
- node.outerHTML = emptyHTML;
873
- } catch (_) {
874
- node.remove();
875
- }
972
+ node.remove();
876
973
  }
877
974
  };
878
975
  /**
@@ -1051,14 +1148,6 @@ function createDOMPurify() {
1051
1148
 
1052
1149
  return true;
1053
1150
  }
1054
- /* Check if tagname contains Unicode */
1055
-
1056
-
1057
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1058
- _forceRemove(currentNode);
1059
-
1060
- return true;
1061
- }
1062
1151
  /* Now let's check the element's type and name */
1063
1152
 
1064
1153
 
@@ -1077,14 +1166,6 @@ function createDOMPurify() {
1077
1166
 
1078
1167
  return true;
1079
1168
  }
1080
- /* Mitigate a problem with templates inside select */
1081
-
1082
-
1083
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1084
- _forceRemove(currentNode);
1085
-
1086
- return true;
1087
- }
1088
1169
  /* Remove element if anything forbids its presence */
1089
1170
 
1090
1171
 
@@ -1122,6 +1203,8 @@ function createDOMPurify() {
1122
1203
 
1123
1204
  return true;
1124
1205
  }
1206
+ /* Make sure that older browsers don't get noscript mXSS */
1207
+
1125
1208
 
1126
1209
  if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1127
1210
  _forceRemove(currentNode);
@@ -1398,7 +1481,6 @@ function createDOMPurify() {
1398
1481
  var body;
1399
1482
  var importedNode;
1400
1483
  var currentNode;
1401
- var oldNode;
1402
1484
  var returnNode;
1403
1485
  /* Make sure we have a string to sanitize.
1404
1486
  DO NOT return early, as this will return the wrong type if
@@ -1424,20 +1506,10 @@ function createDOMPurify() {
1424
1506
  }
1425
1507
  }
1426
1508
  }
1427
- /* Check we can run. Otherwise fall back or ignore */
1509
+ /* Return dirty HTML if DOMPurify cannot run */
1428
1510
 
1429
1511
 
1430
1512
  if (!DOMPurify.isSupported) {
1431
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1432
- if (typeof dirty === 'string') {
1433
- return window.toStaticHTML(dirty);
1434
- }
1435
-
1436
- if (_isNode(dirty)) {
1437
- return window.toStaticHTML(dirty.outerHTML);
1438
- }
1439
- }
1440
-
1441
1513
  return dirty;
1442
1514
  }
1443
1515
  /* Assign config vars */
@@ -1510,13 +1582,7 @@ function createDOMPurify() {
1510
1582
 
1511
1583
 
1512
1584
  while (currentNode = nodeIterator.nextNode()) {
1513
- /* Fix IE's strange behavior with manipulated textNodes #89 */
1514
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
1515
- continue;
1516
- }
1517
1585
  /* Sanitize tags and elements */
1518
-
1519
-
1520
1586
  if (_sanitizeElements(currentNode)) {
1521
1587
  continue;
1522
1588
  }
@@ -1530,13 +1596,10 @@ function createDOMPurify() {
1530
1596
 
1531
1597
 
1532
1598
  _sanitizeAttributes(currentNode);
1533
-
1534
- oldNode = currentNode;
1535
1599
  }
1536
-
1537
- oldNode = null;
1538
1600
  /* If we sanitized `dirty` in-place, return it. */
1539
1601
 
1602
+
1540
1603
  if (IN_PLACE) {
1541
1604
  return dirty;
1542
1605
  }