url-sanitizer 0.10.12 → 0.10.14
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/url-sanitizer.js +60 -57
- package/dist/url-sanitizer.js.map +3 -3
- package/dist/url-sanitizer.min.js +3 -3
- package/dist/url-sanitizer.min.js.map +3 -3
- package/package.json +10 -10
package/dist/url-sanitizer.js
CHANGED
|
@@ -47,11 +47,6 @@ var require_purify = __commonJS({
|
|
|
47
47
|
apply,
|
|
48
48
|
construct
|
|
49
49
|
} = typeof Reflect !== "undefined" && Reflect;
|
|
50
|
-
if (!apply) {
|
|
51
|
-
apply = function apply2(fun, thisValue, args) {
|
|
52
|
-
return fun.apply(thisValue, args);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
50
|
if (!freeze) {
|
|
56
51
|
freeze = function freeze2(x) {
|
|
57
52
|
return x;
|
|
@@ -62,6 +57,11 @@ var require_purify = __commonJS({
|
|
|
62
57
|
return x;
|
|
63
58
|
};
|
|
64
59
|
}
|
|
60
|
+
if (!apply) {
|
|
61
|
+
apply = function apply2(fun, thisValue, args) {
|
|
62
|
+
return fun.apply(thisValue, args);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
65
|
if (!construct) {
|
|
66
66
|
construct = function construct2(Func, args) {
|
|
67
67
|
return new Func(...args);
|
|
@@ -94,9 +94,8 @@ var require_purify = __commonJS({
|
|
|
94
94
|
return construct(func, args);
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
function addToSet(set, array
|
|
98
|
-
|
|
99
|
-
transformCaseFunc = (_transformCaseFunc = transformCaseFunc) !== null && _transformCaseFunc !== void 0 ? _transformCaseFunc : stringToLowerCase;
|
|
97
|
+
function addToSet(set, array) {
|
|
98
|
+
let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
|
|
100
99
|
if (setPrototypeOf) {
|
|
101
100
|
setPrototypeOf(set, null);
|
|
102
101
|
}
|
|
@@ -119,7 +118,9 @@ var require_purify = __commonJS({
|
|
|
119
118
|
function clone(object) {
|
|
120
119
|
const newObject = create(null);
|
|
121
120
|
for (const [property, value] of entries(object)) {
|
|
122
|
-
|
|
121
|
+
if (getOwnPropertyDescriptor(object, property) !== void 0) {
|
|
122
|
+
newObject[property] = value;
|
|
123
|
+
}
|
|
123
124
|
}
|
|
124
125
|
return newObject;
|
|
125
126
|
}
|
|
@@ -180,7 +181,9 @@ var require_purify = __commonJS({
|
|
|
180
181
|
ATTR_WHITESPACE,
|
|
181
182
|
DOCTYPE_NAME
|
|
182
183
|
});
|
|
183
|
-
const getGlobal = ()
|
|
184
|
+
const getGlobal = function getGlobal2() {
|
|
185
|
+
return typeof window === "undefined" ? null : window;
|
|
186
|
+
};
|
|
184
187
|
const _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
|
|
185
188
|
if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
|
|
186
189
|
return null;
|
|
@@ -208,17 +211,17 @@ var require_purify = __commonJS({
|
|
|
208
211
|
function createDOMPurify() {
|
|
209
212
|
let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
|
|
210
213
|
const DOMPurify = (root) => createDOMPurify(root);
|
|
211
|
-
DOMPurify.version = "3.0.
|
|
214
|
+
DOMPurify.version = "3.0.6";
|
|
212
215
|
DOMPurify.removed = [];
|
|
213
216
|
if (!window2 || !window2.document || window2.document.nodeType !== 9) {
|
|
214
217
|
DOMPurify.isSupported = false;
|
|
215
218
|
return DOMPurify;
|
|
216
219
|
}
|
|
217
|
-
const originalDocument = window2.document;
|
|
218
|
-
const currentScript = originalDocument.currentScript;
|
|
219
220
|
let {
|
|
220
221
|
document
|
|
221
222
|
} = window2;
|
|
223
|
+
const originalDocument = document;
|
|
224
|
+
const currentScript = originalDocument.currentScript;
|
|
222
225
|
const {
|
|
223
226
|
DocumentFragment,
|
|
224
227
|
HTMLTemplateElement,
|
|
@@ -270,7 +273,7 @@ var require_purify = __commonJS({
|
|
|
270
273
|
const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
|
|
271
274
|
let ALLOWED_ATTR = null;
|
|
272
275
|
const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
|
|
273
|
-
let CUSTOM_ELEMENT_HANDLING = Object.seal(
|
|
276
|
+
let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
|
|
274
277
|
tagNameCheck: {
|
|
275
278
|
writable: true,
|
|
276
279
|
configurable: false,
|
|
@@ -322,16 +325,17 @@ var require_purify = __commonJS({
|
|
|
322
325
|
let IS_EMPTY_INPUT = false;
|
|
323
326
|
let ALLOWED_NAMESPACES = null;
|
|
324
327
|
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
|
|
325
|
-
let PARSER_MEDIA_TYPE;
|
|
328
|
+
let PARSER_MEDIA_TYPE = null;
|
|
326
329
|
const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
|
|
327
330
|
const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
|
|
328
|
-
let transformCaseFunc;
|
|
331
|
+
let transformCaseFunc = null;
|
|
329
332
|
let CONFIG = null;
|
|
330
333
|
const formElement = document.createElement("form");
|
|
331
334
|
const isRegexOrFunction = function isRegexOrFunction2(testValue) {
|
|
332
335
|
return testValue instanceof RegExp || testValue instanceof Function;
|
|
333
336
|
};
|
|
334
|
-
const _parseConfig = function _parseConfig2(
|
|
337
|
+
const _parseConfig = function _parseConfig2() {
|
|
338
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
335
339
|
if (CONFIG && CONFIG === cfg) {
|
|
336
340
|
return;
|
|
337
341
|
}
|
|
@@ -564,8 +568,8 @@ var require_purify = __commonJS({
|
|
|
564
568
|
}
|
|
565
569
|
};
|
|
566
570
|
const _initDocument = function _initDocument2(dirty) {
|
|
567
|
-
let doc;
|
|
568
|
-
let leadingWhitespace;
|
|
571
|
+
let doc = null;
|
|
572
|
+
let leadingWhitespace = null;
|
|
569
573
|
if (FORCE_BODY) {
|
|
570
574
|
dirty = "<remove></remove>" + dirty;
|
|
571
575
|
} else {
|
|
@@ -598,21 +602,20 @@ var require_purify = __commonJS({
|
|
|
598
602
|
}
|
|
599
603
|
return WHOLE_DOCUMENT ? doc.documentElement : body;
|
|
600
604
|
};
|
|
601
|
-
const
|
|
605
|
+
const _createNodeIterator = function _createNodeIterator2(root) {
|
|
602
606
|
return createNodeIterator.call(
|
|
603
607
|
root.ownerDocument || root,
|
|
604
608
|
root,
|
|
605
609
|
// eslint-disable-next-line no-bitwise
|
|
606
610
|
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,
|
|
607
|
-
null
|
|
608
|
-
false
|
|
611
|
+
null
|
|
609
612
|
);
|
|
610
613
|
};
|
|
611
614
|
const _isClobbered = function _isClobbered2(elm) {
|
|
612
615
|
return elm instanceof HTMLFormElement && (typeof elm.nodeName !== "string" || typeof elm.textContent !== "string" || typeof elm.removeChild !== "function" || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== "function" || typeof elm.setAttribute !== "function" || typeof elm.namespaceURI !== "string" || typeof elm.insertBefore !== "function" || typeof elm.hasChildNodes !== "function");
|
|
613
616
|
};
|
|
614
617
|
const _isNode = function _isNode2(object) {
|
|
615
|
-
return typeof Node === "
|
|
618
|
+
return typeof Node === "function" && object instanceof Node;
|
|
616
619
|
};
|
|
617
620
|
const _executeHook = function _executeHook2(entryPoint, currentNode, data) {
|
|
618
621
|
if (!hooks[entryPoint]) {
|
|
@@ -623,7 +626,7 @@ var require_purify = __commonJS({
|
|
|
623
626
|
});
|
|
624
627
|
};
|
|
625
628
|
const _sanitizeElements = function _sanitizeElements2(currentNode) {
|
|
626
|
-
let content;
|
|
629
|
+
let content = null;
|
|
627
630
|
_executeHook("beforeSanitizeElements", currentNode, null);
|
|
628
631
|
if (_isClobbered(currentNode)) {
|
|
629
632
|
_forceRemove(currentNode);
|
|
@@ -634,16 +637,18 @@ var require_purify = __commonJS({
|
|
|
634
637
|
tagName,
|
|
635
638
|
allowedTags: ALLOWED_TAGS
|
|
636
639
|
});
|
|
637
|
-
if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) &&
|
|
640
|
+
if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
|
|
638
641
|
_forceRemove(currentNode);
|
|
639
642
|
return true;
|
|
640
643
|
}
|
|
641
644
|
if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
|
642
|
-
if (!FORBID_TAGS[tagName] &&
|
|
643
|
-
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName))
|
|
645
|
+
if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
|
|
646
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
|
|
644
647
|
return false;
|
|
645
|
-
|
|
648
|
+
}
|
|
649
|
+
if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
|
|
646
650
|
return false;
|
|
651
|
+
}
|
|
647
652
|
}
|
|
648
653
|
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
|
|
649
654
|
const parentNode = getParentNode(currentNode) || currentNode.parentNode;
|
|
@@ -668,9 +673,9 @@ var require_purify = __commonJS({
|
|
|
668
673
|
}
|
|
669
674
|
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
|
|
670
675
|
content = currentNode.textContent;
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
676
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
677
|
+
content = stringReplace(content, expr, " ");
|
|
678
|
+
});
|
|
674
679
|
if (currentNode.textContent !== content) {
|
|
675
680
|
arrayPush(DOMPurify.removed, {
|
|
676
681
|
element: currentNode.cloneNode()
|
|
@@ -694,7 +699,7 @@ var require_purify = __commonJS({
|
|
|
694
699
|
// First condition does a very basic check if a) it's basically a valid custom element tagname AND
|
|
695
700
|
// b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
696
701
|
// and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
|
|
697
|
-
|
|
702
|
+
_isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
|
|
698
703
|
// the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
|
|
699
704
|
lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))
|
|
700
705
|
)
|
|
@@ -716,14 +721,10 @@ var require_purify = __commonJS({
|
|
|
716
721
|
;
|
|
717
722
|
return true;
|
|
718
723
|
};
|
|
719
|
-
const
|
|
724
|
+
const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
|
|
720
725
|
return tagName.indexOf("-") > 0;
|
|
721
726
|
};
|
|
722
727
|
const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
|
|
723
|
-
let attr;
|
|
724
|
-
let value;
|
|
725
|
-
let lcName;
|
|
726
|
-
let l;
|
|
727
728
|
_executeHook("beforeSanitizeAttributes", currentNode, null);
|
|
728
729
|
const {
|
|
729
730
|
attributes
|
|
@@ -737,15 +738,16 @@ var require_purify = __commonJS({
|
|
|
737
738
|
keepAttr: true,
|
|
738
739
|
allowedAttributes: ALLOWED_ATTR
|
|
739
740
|
};
|
|
740
|
-
l = attributes.length;
|
|
741
|
+
let l = attributes.length;
|
|
741
742
|
while (l--) {
|
|
742
|
-
attr = attributes[l];
|
|
743
|
+
const attr = attributes[l];
|
|
743
744
|
const {
|
|
744
745
|
name,
|
|
745
|
-
namespaceURI
|
|
746
|
+
namespaceURI,
|
|
747
|
+
value: attrValue
|
|
746
748
|
} = attr;
|
|
747
|
-
|
|
748
|
-
|
|
749
|
+
const lcName = transformCaseFunc(name);
|
|
750
|
+
let value = name === "value" ? attrValue : stringTrim(attrValue);
|
|
749
751
|
hookEvent.attrName = lcName;
|
|
750
752
|
hookEvent.attrValue = value;
|
|
751
753
|
hookEvent.keepAttr = true;
|
|
@@ -764,9 +766,9 @@ var require_purify = __commonJS({
|
|
|
764
766
|
continue;
|
|
765
767
|
}
|
|
766
768
|
if (SAFE_FOR_TEMPLATES) {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
769
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
770
|
+
value = stringReplace(value, expr, " ");
|
|
771
|
+
});
|
|
770
772
|
}
|
|
771
773
|
const lcTag = transformCaseFunc(currentNode.nodeName);
|
|
772
774
|
if (!_isValidAttribute(lcTag, lcName, value)) {
|
|
@@ -805,8 +807,8 @@ var require_purify = __commonJS({
|
|
|
805
807
|
_executeHook("afterSanitizeAttributes", currentNode, null);
|
|
806
808
|
};
|
|
807
809
|
const _sanitizeShadowDOM = function _sanitizeShadowDOM2(fragment) {
|
|
808
|
-
let shadowNode;
|
|
809
|
-
const shadowIterator =
|
|
810
|
+
let shadowNode = null;
|
|
811
|
+
const shadowIterator = _createNodeIterator(fragment);
|
|
810
812
|
_executeHook("beforeSanitizeShadowDOM", fragment, null);
|
|
811
813
|
while (shadowNode = shadowIterator.nextNode()) {
|
|
812
814
|
_executeHook("uponSanitizeShadowNode", shadowNode, null);
|
|
@@ -822,10 +824,10 @@ var require_purify = __commonJS({
|
|
|
822
824
|
};
|
|
823
825
|
DOMPurify.sanitize = function(dirty) {
|
|
824
826
|
let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
825
|
-
let body;
|
|
826
|
-
let importedNode;
|
|
827
|
-
let currentNode;
|
|
828
|
-
let returnNode;
|
|
827
|
+
let body = null;
|
|
828
|
+
let importedNode = null;
|
|
829
|
+
let currentNode = null;
|
|
830
|
+
let returnNode = null;
|
|
829
831
|
IS_EMPTY_INPUT = !dirty;
|
|
830
832
|
if (IS_EMPTY_INPUT) {
|
|
831
833
|
dirty = "<!-->";
|
|
@@ -880,7 +882,7 @@ var require_purify = __commonJS({
|
|
|
880
882
|
if (body && FORCE_BODY) {
|
|
881
883
|
_forceRemove(body.firstChild);
|
|
882
884
|
}
|
|
883
|
-
const nodeIterator =
|
|
885
|
+
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
|
|
884
886
|
while (currentNode = nodeIterator.nextNode()) {
|
|
885
887
|
if (_sanitizeElements(currentNode)) {
|
|
886
888
|
continue;
|
|
@@ -912,13 +914,14 @@ var require_purify = __commonJS({
|
|
|
912
914
|
serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
|
|
913
915
|
}
|
|
914
916
|
if (SAFE_FOR_TEMPLATES) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
917
|
+
arrayForEach([MUSTACHE_EXPR2, ERB_EXPR2, TMPLIT_EXPR2], (expr) => {
|
|
918
|
+
serializedHTML = stringReplace(serializedHTML, expr, " ");
|
|
919
|
+
});
|
|
918
920
|
}
|
|
919
921
|
return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
|
920
922
|
};
|
|
921
|
-
DOMPurify.setConfig = function(
|
|
923
|
+
DOMPurify.setConfig = function() {
|
|
924
|
+
let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
922
925
|
_parseConfig(cfg);
|
|
923
926
|
SET_CONFIG = true;
|
|
924
927
|
};
|
|
@@ -1593,6 +1596,6 @@ export {
|
|
|
1593
1596
|
/*! Bundled license information:
|
|
1594
1597
|
|
|
1595
1598
|
dompurify/dist/purify.js:
|
|
1596
|
-
(*! @license DOMPurify 3.0.
|
|
1599
|
+
(*! @license DOMPurify 3.0.6 | (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.6/LICENSE *)
|
|
1597
1600
|
*/
|
|
1598
1601
|
//# sourceMappingURL=url-sanitizer.js.map
|