url-sanitizer 0.8.5 → 0.8.9

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/README.md CHANGED
@@ -21,14 +21,13 @@ npm i url-sanitizer
21
21
  For browsers and web sites, standalone ESM builds are available in `dist/` directory.
22
22
  * node_modules/url-sanitizer/dist/url-sanitizer.js
23
23
  * node_modules/url-sanitizer/dist/url-sanitizer.min.js
24
- * node_modules/url-sanitizer/dist/url-sanitizer.wo.dompurify.js
25
- * node_modules/url-sanitizer/dist/url-sanitizer.wo.dompurify.min.js
24
+ * node_modules/url-sanitizer/dist/url-sanitizer-wo-dompurify.js
25
+ * node_modules/url-sanitizer/dist/url-sanitizer-wo-dompurify.min.js
26
26
 
27
27
  Or, download them from [Releases](https://github.com/asamuzaK/urlSanitizer/releases).
28
28
 
29
- NOTE: `url-sanitizer.wo.dompurify.js` and `url-sanitizer.wo.dompurify.min.js` are built without [DOMPurify](https://www.npmjs.com/package/dompurify).
30
- Use them if DOMPurify is exposed as `window.DOMPurify`.
31
-
29
+ NOTE: `url-sanitizer-wo-dompurify.js` and `url-sanitizer-wo-dompurify.min.js` are built without [DOMPurify](https://www.npmjs.com/package/dompurify).
30
+ If you use them, make sure DOMPurify is exposed as `window.DOMPurify`.
32
31
 
33
32
  ## Usage
34
33
 
@@ -77,6 +77,9 @@ var require_purify = __commonJS({
77
77
  }
78
78
  return _construct.apply(null, arguments);
79
79
  }
80
+ function _slicedToArray(arr, i) {
81
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
82
+ }
80
83
  function _toConsumableArray(arr) {
81
84
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
82
85
  }
@@ -84,10 +87,42 @@ var require_purify = __commonJS({
84
87
  if (Array.isArray(arr))
85
88
  return _arrayLikeToArray(arr);
86
89
  }
90
+ function _arrayWithHoles(arr) {
91
+ if (Array.isArray(arr))
92
+ return arr;
93
+ }
87
94
  function _iterableToArray(iter) {
88
95
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
89
96
  return Array.from(iter);
90
97
  }
98
+ function _iterableToArrayLimit(arr, i) {
99
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
100
+ if (_i == null)
101
+ return;
102
+ var _arr = [];
103
+ var _n = true;
104
+ var _d = false;
105
+ var _s, _e;
106
+ try {
107
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
108
+ _arr.push(_s.value);
109
+ if (i && _arr.length === i)
110
+ break;
111
+ }
112
+ } catch (err) {
113
+ _d = true;
114
+ _e = err;
115
+ } finally {
116
+ try {
117
+ if (!_n && _i["return"] != null)
118
+ _i["return"]();
119
+ } finally {
120
+ if (_d)
121
+ throw _e;
122
+ }
123
+ }
124
+ return _arr;
125
+ }
91
126
  function _unsupportedIterableToArray(o, minLen) {
92
127
  if (!o)
93
128
  return;
@@ -111,7 +146,64 @@ var require_purify = __commonJS({
111
146
  function _nonIterableSpread() {
112
147
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
113
148
  }
114
- var hasOwnProperty = Object.hasOwnProperty, setPrototypeOf = Object.setPrototypeOf, isFrozen = Object.isFrozen, getPrototypeOf = Object.getPrototypeOf, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
149
+ function _nonIterableRest() {
150
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
151
+ }
152
+ function _createForOfIteratorHelper(o, allowArrayLike) {
153
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
154
+ if (!it) {
155
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
156
+ if (it)
157
+ o = it;
158
+ var i = 0;
159
+ var F = function() {
160
+ };
161
+ return {
162
+ s: F,
163
+ n: function() {
164
+ if (i >= o.length)
165
+ return {
166
+ done: true
167
+ };
168
+ return {
169
+ done: false,
170
+ value: o[i++]
171
+ };
172
+ },
173
+ e: function(e) {
174
+ throw e;
175
+ },
176
+ f: F
177
+ };
178
+ }
179
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
180
+ }
181
+ var normalCompletion = true, didErr = false, err;
182
+ return {
183
+ s: function() {
184
+ it = it.call(o);
185
+ },
186
+ n: function() {
187
+ var step = it.next();
188
+ normalCompletion = step.done;
189
+ return step;
190
+ },
191
+ e: function(e) {
192
+ didErr = true;
193
+ err = e;
194
+ },
195
+ f: function() {
196
+ try {
197
+ if (!normalCompletion && it.return != null)
198
+ it.return();
199
+ } finally {
200
+ if (didErr)
201
+ throw err;
202
+ }
203
+ }
204
+ };
205
+ }
206
+ var entries = Object.entries, setPrototypeOf = Object.setPrototypeOf, isFrozen = Object.isFrozen, getPrototypeOf = Object.getPrototypeOf, getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
115
207
  var freeze = Object.freeze, seal = Object.seal, create = Object.create;
116
208
  var _ref = typeof Reflect !== "undefined" && Reflect, apply = _ref.apply, construct = _ref.construct;
117
209
  if (!apply) {
@@ -184,11 +276,16 @@ var require_purify = __commonJS({
184
276
  }
185
277
  function clone(object) {
186
278
  var newObject = create(null);
187
- var property;
188
- for (property in object) {
189
- if (apply(hasOwnProperty, object, [property]) === true) {
190
- newObject[property] = object[property];
191
- }
279
+ var _iterator = _createForOfIteratorHelper(entries(object)), _step;
280
+ try {
281
+ for (_iterator.s(); !(_step = _iterator.n()).done; ) {
282
+ var _step$value = _slicedToArray(_step.value, 2), property = _step$value[0], value = _step$value[1];
283
+ newObject[property] = value;
284
+ }
285
+ } catch (err) {
286
+ _iterator.e(err);
287
+ } finally {
288
+ _iterator.f();
192
289
  }
193
290
  return newObject;
194
291
  }
@@ -269,7 +366,7 @@ var require_purify = __commonJS({
269
366
  var DOMPurify = function DOMPurify2(root) {
270
367
  return createDOMPurify(root);
271
368
  };
272
- DOMPurify.version = "2.4.3";
369
+ DOMPurify.version = "3.0.0";
273
370
  DOMPurify.removed = [];
274
371
  if (!window2 || !window2.document || window2.document.nodeType !== 9) {
275
372
  DOMPurify.isSupported = false;
@@ -293,13 +390,8 @@ var require_purify = __commonJS({
293
390
  var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML("") : "";
294
391
  var _document = document, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
295
392
  var importNode = originalDocument.importNode;
296
- var documentMode = {};
297
- try {
298
- documentMode = clone(document).documentMode ? document.documentMode : {};
299
- } catch (_) {
300
- }
301
393
  var hooks = {};
302
- DOMPurify.isSupported = typeof getParentNode === "function" && implementation && typeof implementation.createHTMLDocument !== "undefined" && documentMode !== 9;
394
+ DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && typeof implementation.createHTMLDocument !== "undefined";
303
395
  var MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, TMPLIT_EXPR$1 = TMPLIT_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE;
304
396
  var IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
305
397
  var ALLOWED_TAGS = null;
@@ -331,6 +423,7 @@ var require_purify = __commonJS({
331
423
  var ALLOW_ARIA_ATTR = true;
332
424
  var ALLOW_DATA_ATTR = true;
333
425
  var ALLOW_UNKNOWN_PROTOCOLS = false;
426
+ var ALLOW_SELF_CLOSE_IN_ATTR = true;
334
427
  var SAFE_FOR_TEMPLATES = false;
335
428
  var WHOLE_DOCUMENT = false;
336
429
  var SET_CONFIG = false;
@@ -403,6 +496,7 @@ var require_purify = __commonJS({
403
496
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
404
497
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
405
498
  ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
499
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
406
500
  SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
407
501
  WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
408
502
  RETURN_DOM = cfg.RETURN_DOM || false;
@@ -549,11 +643,7 @@ var require_purify = __commonJS({
549
643
  try {
550
644
  node.parentNode.removeChild(node);
551
645
  } catch (_) {
552
- try {
553
- node.outerHTML = emptyHTML;
554
- } catch (_2) {
555
- node.remove();
556
- }
646
+ node.remove();
557
647
  }
558
648
  };
559
649
  var _removeAttribute = function _removeAttribute2(name, node) {
@@ -649,10 +739,6 @@ var require_purify = __commonJS({
649
739
  _forceRemove(currentNode);
650
740
  return true;
651
741
  }
652
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
653
- _forceRemove(currentNode);
654
- return true;
655
- }
656
742
  var tagName = transformCaseFunc(currentNode.nodeName);
657
743
  _executeHook("uponSanitizeElement", currentNode, {
658
744
  tagName,
@@ -662,10 +748,6 @@ var require_purify = __commonJS({
662
748
  _forceRemove(currentNode);
663
749
  return true;
664
750
  }
665
- if (tagName === "select" && regExpTest(/<template/i, currentNode.innerHTML)) {
666
- _forceRemove(currentNode);
667
- return true;
668
- }
669
751
  if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
670
752
  if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
671
753
  if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName))
@@ -783,7 +865,7 @@ var require_purify = __commonJS({
783
865
  if (!hookEvent.keepAttr) {
784
866
  continue;
785
867
  }
786
- if (regExpTest(/\/>/i, value)) {
868
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
787
869
  _removeAttribute(name, currentNode);
788
870
  continue;
789
871
  }
@@ -847,7 +929,6 @@ var require_purify = __commonJS({
847
929
  var body;
848
930
  var importedNode;
849
931
  var currentNode;
850
- var oldNode;
851
932
  var returnNode;
852
933
  IS_EMPTY_INPUT = !dirty;
853
934
  if (IS_EMPTY_INPUT) {
@@ -864,14 +945,6 @@ var require_purify = __commonJS({
864
945
  }
865
946
  }
866
947
  if (!DOMPurify.isSupported) {
867
- if (_typeof(window2.toStaticHTML) === "object" || typeof window2.toStaticHTML === "function") {
868
- if (typeof dirty === "string") {
869
- return window2.toStaticHTML(dirty);
870
- }
871
- if (_isNode(dirty)) {
872
- return window2.toStaticHTML(dirty.outerHTML);
873
- }
874
- }
875
948
  return dirty;
876
949
  }
877
950
  if (!SET_CONFIG) {
@@ -913,9 +986,6 @@ var require_purify = __commonJS({
913
986
  }
914
987
  var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
915
988
  while (currentNode = nodeIterator.nextNode()) {
916
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
917
- continue;
918
- }
919
989
  if (_sanitizeElements(currentNode)) {
920
990
  continue;
921
991
  }
@@ -923,9 +993,7 @@ var require_purify = __commonJS({
923
993
  _sanitizeShadowDOM(currentNode.content);
924
994
  }
925
995
  _sanitizeAttributes(currentNode);
926
- oldNode = currentNode;
927
996
  }
928
- oldNode = null;
929
997
  if (IN_PLACE) {
930
998
  return dirty;
931
999
  }
@@ -938,7 +1006,7 @@ var require_purify = __commonJS({
938
1006
  } else {
939
1007
  returnNode = body;
940
1008
  }
941
- if (ALLOWED_ATTR.shadowroot) {
1009
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
942
1010
  returnNode = importNode.call(originalDocument, returnNode, true);
943
1011
  }
944
1012
  return returnNode;
@@ -2192,6 +2260,6 @@ export {
2192
2260
  /*! Bundled license information:
2193
2261
 
2194
2262
  dompurify/dist/purify.js:
2195
- (*! @license DOMPurify 2.4.3 | (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.3/LICENSE *)
2263
+ (*! @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 *)
2196
2264
  */
2197
2265
  //# sourceMappingURL=url-sanitizer.js.map