ztxkutils 2.6.1 → 2.6.4

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.
@@ -1,1609 +0,0 @@
1
- /*! @license DOMPurify 2.3.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.8/LICENSE */
2
-
3
- function _typeof(obj) {
4
- "@babel/helpers - typeof";
5
-
6
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
7
- return typeof obj;
8
- } : function (obj) {
9
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
10
- }, _typeof(obj);
11
- }
12
-
13
- function _setPrototypeOf(o, p) {
14
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
15
- o.__proto__ = p;
16
- return o;
17
- };
18
-
19
- return _setPrototypeOf(o, p);
20
- }
21
-
22
- function _isNativeReflectConstruct() {
23
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
24
- if (Reflect.construct.sham) return false;
25
- if (typeof Proxy === "function") return true;
26
-
27
- try {
28
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
29
- return true;
30
- } catch (e) {
31
- return false;
32
- }
33
- }
34
-
35
- function _construct(Parent, args, Class) {
36
- if (_isNativeReflectConstruct()) {
37
- _construct = Reflect.construct;
38
- } else {
39
- _construct = function _construct(Parent, args, Class) {
40
- var a = [null];
41
- a.push.apply(a, args);
42
- var Constructor = Function.bind.apply(Parent, a);
43
- var instance = new Constructor();
44
- if (Class) _setPrototypeOf(instance, Class.prototype);
45
- return instance;
46
- };
47
- }
48
-
49
- return _construct.apply(null, arguments);
50
- }
51
-
52
- function _toConsumableArray(arr) {
53
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
54
- }
55
-
56
- function _arrayWithoutHoles(arr) {
57
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
58
- }
59
-
60
- function _iterableToArray(iter) {
61
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
62
- }
63
-
64
- function _unsupportedIterableToArray(o, minLen) {
65
- if (!o) return;
66
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
67
- var n = Object.prototype.toString.call(o).slice(8, -1);
68
- if (n === "Object" && o.constructor) n = o.constructor.name;
69
- if (n === "Map" || n === "Set") return Array.from(o);
70
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
71
- }
72
-
73
- function _arrayLikeToArray(arr, len) {
74
- if (len == null || len > arr.length) len = arr.length;
75
-
76
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
77
-
78
- return arr2;
79
- }
80
-
81
- function _nonIterableSpread() {
82
- 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
- }
84
-
85
- var hasOwnProperty = Object.hasOwnProperty,
86
- setPrototypeOf = Object.setPrototypeOf,
87
- isFrozen = Object.isFrozen,
88
- getPrototypeOf = Object.getPrototypeOf,
89
- getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
90
- var freeze = Object.freeze,
91
- seal = Object.seal,
92
- create = Object.create; // eslint-disable-line import/no-mutable-exports
93
-
94
- var _ref = typeof Reflect !== 'undefined' && Reflect,
95
- apply = _ref.apply,
96
- construct = _ref.construct;
97
-
98
- if (!apply) {
99
- apply = function apply(fun, thisValue, args) {
100
- return fun.apply(thisValue, args);
101
- };
102
- }
103
-
104
- if (!freeze) {
105
- freeze = function freeze(x) {
106
- return x;
107
- };
108
- }
109
-
110
- if (!seal) {
111
- seal = function seal(x) {
112
- return x;
113
- };
114
- }
115
-
116
- if (!construct) {
117
- construct = function construct(Func, args) {
118
- return _construct(Func, _toConsumableArray(args));
119
- };
120
- }
121
-
122
- var arrayForEach = unapply(Array.prototype.forEach);
123
- var arrayPop = unapply(Array.prototype.pop);
124
- var arrayPush = unapply(Array.prototype.push);
125
- var stringToLowerCase = unapply(String.prototype.toLowerCase);
126
- var stringMatch = unapply(String.prototype.match);
127
- var stringReplace = unapply(String.prototype.replace);
128
- var stringIndexOf = unapply(String.prototype.indexOf);
129
- var stringTrim = unapply(String.prototype.trim);
130
- var regExpTest = unapply(RegExp.prototype.test);
131
- var typeErrorCreate = unconstruct(TypeError);
132
- function unapply(func) {
133
- return function (thisArg) {
134
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
135
- args[_key - 1] = arguments[_key];
136
- }
137
-
138
- return apply(func, thisArg, args);
139
- };
140
- }
141
- function unconstruct(func) {
142
- return function () {
143
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
144
- args[_key2] = arguments[_key2];
145
- }
146
-
147
- return construct(func, args);
148
- };
149
- }
150
- /* Add properties to a lookup table */
151
-
152
- function addToSet(set, array) {
153
- if (setPrototypeOf) {
154
- // Make 'in' and truthy checks like Boolean(set.constructor)
155
- // independent of any properties defined on Object.prototype.
156
- // Prevent prototype setters from intercepting set as a this value.
157
- setPrototypeOf(set, null);
158
- }
159
-
160
- var l = array.length;
161
-
162
- while (l--) {
163
- var element = array[l];
164
-
165
- if (typeof element === 'string') {
166
- var lcElement = stringToLowerCase(element);
167
-
168
- if (lcElement !== element) {
169
- // Config presets (e.g. tags.js, attrs.js) are immutable.
170
- if (!isFrozen(array)) {
171
- array[l] = lcElement;
172
- }
173
-
174
- element = lcElement;
175
- }
176
- }
177
-
178
- set[element] = true;
179
- }
180
-
181
- return set;
182
- }
183
- /* Shallow clone an object */
184
-
185
- function clone(object) {
186
- var newObject = create(null);
187
- var property;
188
-
189
- for (property in object) {
190
- if (apply(hasOwnProperty, object, [property])) {
191
- newObject[property] = object[property];
192
- }
193
- }
194
-
195
- return newObject;
196
- }
197
- /* IE10 doesn't support __lookupGetter__ so lets'
198
- * simulate it. It also automatically checks
199
- * if the prop is function or getter and behaves
200
- * accordingly. */
201
-
202
- function lookupGetter(object, prop) {
203
- while (object !== null) {
204
- var desc = getOwnPropertyDescriptor(object, prop);
205
-
206
- if (desc) {
207
- if (desc.get) {
208
- return unapply(desc.get);
209
- }
210
-
211
- if (typeof desc.value === 'function') {
212
- return unapply(desc.value);
213
- }
214
- }
215
-
216
- object = getPrototypeOf(object);
217
- }
218
-
219
- function fallbackValue(element) {
220
- console.warn('fallback value for', element);
221
- return null;
222
- }
223
-
224
- return fallbackValue;
225
- }
226
-
227
- var html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); // SVG
228
-
229
- var svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
230
- var svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default.
231
- // We still need to know them so that we can do namespace
232
- // checks properly in case one wants to add them to
233
- // allow-list.
234
-
235
- var svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'fedropshadow', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
236
- var mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover']); // Similarly to SVG, we want to know all MathML elements,
237
- // even those that we disallow by default.
238
-
239
- var mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
240
- var text = freeze(['#text']);
241
-
242
- var html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
243
- var svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
244
- var mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
245
- var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
246
-
247
- var MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
248
-
249
- var ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
250
- var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
251
-
252
- var ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
253
-
254
- var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
255
- );
256
- var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
257
- var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
258
- );
259
- var DOCTYPE_NAME = seal(/^html$/i);
260
-
261
- var getGlobal = function getGlobal() {
262
- return typeof window === 'undefined' ? null : window;
263
- };
264
- /**
265
- * Creates a no-op policy for internal use only.
266
- * Don't export this function outside this module!
267
- * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
268
- * @param {Document} document The document object (to determine policy name suffix)
269
- * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
270
- * are not supported).
271
- */
272
-
273
-
274
- var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
275
- if (_typeof(trustedTypes) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
276
- return null;
277
- } // Allow the callers to control the unique policy name
278
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
279
- // Policy creation with duplicate names throws in Trusted Types.
280
-
281
-
282
- var suffix = null;
283
- var ATTR_NAME = 'data-tt-policy-suffix';
284
-
285
- if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
286
- suffix = document.currentScript.getAttribute(ATTR_NAME);
287
- }
288
-
289
- var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
290
-
291
- try {
292
- return trustedTypes.createPolicy(policyName, {
293
- createHTML: function createHTML(html) {
294
- return html;
295
- }
296
- });
297
- } catch (_) {
298
- // Policy creation failed (most likely another DOMPurify script has
299
- // already run). Skip creating the policy, as this will only cause errors
300
- // if TT are enforced.
301
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
302
- return null;
303
- }
304
- };
305
-
306
- function createDOMPurify() {
307
- var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
308
-
309
- var DOMPurify = function DOMPurify(root) {
310
- return createDOMPurify(root);
311
- };
312
- /**
313
- * Version label, exposed for easier checks
314
- * if DOMPurify is up to date or not
315
- */
316
-
317
-
318
- DOMPurify.version = '2.3.8';
319
- /**
320
- * Array of elements that DOMPurify removed during sanitation.
321
- * Empty if nothing was removed.
322
- */
323
-
324
- DOMPurify.removed = [];
325
-
326
- if (!window || !window.document || window.document.nodeType !== 9) {
327
- // Not running in a browser, provide a factory function
328
- // so that you can pass your own Window
329
- DOMPurify.isSupported = false;
330
- return DOMPurify;
331
- }
332
-
333
- var originalDocument = window.document;
334
- var document = window.document;
335
- var DocumentFragment = window.DocumentFragment,
336
- HTMLTemplateElement = window.HTMLTemplateElement,
337
- Node = window.Node,
338
- Element = window.Element,
339
- NodeFilter = window.NodeFilter,
340
- _window$NamedNodeMap = window.NamedNodeMap,
341
- NamedNodeMap = _window$NamedNodeMap === void 0 ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
342
- HTMLFormElement = window.HTMLFormElement,
343
- DOMParser = window.DOMParser,
344
- trustedTypes = window.trustedTypes;
345
- var ElementPrototype = Element.prototype;
346
- var cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
347
- var getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
348
- var getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
349
- var getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
350
- // new document created via createHTMLDocument. As per the spec
351
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
352
- // a new empty registry is used when creating a template contents owner
353
- // document, so we use that as our parent document to ensure nothing
354
- // is inherited.
355
-
356
- if (typeof HTMLTemplateElement === 'function') {
357
- var template = document.createElement('template');
358
-
359
- if (template.content && template.content.ownerDocument) {
360
- document = template.content.ownerDocument;
361
- }
362
- }
363
-
364
- var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
365
-
366
- var emptyHTML = trustedTypesPolicy ? trustedTypesPolicy.createHTML('') : '';
367
- var _document = document,
368
- implementation = _document.implementation,
369
- createNodeIterator = _document.createNodeIterator,
370
- createDocumentFragment = _document.createDocumentFragment,
371
- getElementsByTagName = _document.getElementsByTagName;
372
- var importNode = originalDocument.importNode;
373
- var documentMode = {};
374
-
375
- try {
376
- documentMode = clone(document).documentMode ? document.documentMode : {};
377
- } catch (_) {}
378
-
379
- var hooks = {};
380
- /**
381
- * Expose whether this browser supports running the full DOMPurify.
382
- */
383
-
384
- DOMPurify.isSupported = typeof getParentNode === 'function' && implementation && typeof implementation.createHTMLDocument !== 'undefined' && documentMode !== 9;
385
- var MUSTACHE_EXPR$1 = MUSTACHE_EXPR,
386
- ERB_EXPR$1 = ERB_EXPR,
387
- DATA_ATTR$1 = DATA_ATTR,
388
- ARIA_ATTR$1 = ARIA_ATTR,
389
- IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA,
390
- ATTR_WHITESPACE$1 = ATTR_WHITESPACE;
391
- var IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
392
- /**
393
- * We consider the elements and attributes below to be safe. Ideally
394
- * don't add any new ones but feel free to remove unwanted ones.
395
- */
396
-
397
- /* allowed element names */
398
-
399
- var ALLOWED_TAGS = null;
400
- var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray(html$1), _toConsumableArray(svg$1), _toConsumableArray(svgFilters), _toConsumableArray(mathMl$1), _toConsumableArray(text)));
401
- /* Allowed attribute names */
402
-
403
- var ALLOWED_ATTR = null;
404
- var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray(html), _toConsumableArray(svg), _toConsumableArray(mathMl), _toConsumableArray(xml)));
405
- /*
406
- * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
407
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
408
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
409
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
410
- */
411
-
412
- var CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
413
- tagNameCheck: {
414
- writable: true,
415
- configurable: false,
416
- enumerable: true,
417
- value: null
418
- },
419
- attributeNameCheck: {
420
- writable: true,
421
- configurable: false,
422
- enumerable: true,
423
- value: null
424
- },
425
- allowCustomizedBuiltInElements: {
426
- writable: true,
427
- configurable: false,
428
- enumerable: true,
429
- value: false
430
- }
431
- }));
432
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
433
-
434
- var FORBID_TAGS = null;
435
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
436
-
437
- var FORBID_ATTR = null;
438
- /* Decide if ARIA attributes are okay */
439
-
440
- var ALLOW_ARIA_ATTR = true;
441
- /* Decide if custom data attributes are okay */
442
-
443
- var ALLOW_DATA_ATTR = true;
444
- /* Decide if unknown protocols are okay */
445
-
446
- var ALLOW_UNKNOWN_PROTOCOLS = false;
447
- /* Output should be safe for common template engines.
448
- * This means, DOMPurify removes data attributes, mustaches and ERB
449
- */
450
-
451
- var SAFE_FOR_TEMPLATES = false;
452
- /* Decide if document with <html>... should be returned */
453
-
454
- var WHOLE_DOCUMENT = false;
455
- /* Track whether config is already set on this instance of DOMPurify. */
456
-
457
- var SET_CONFIG = false;
458
- /* Decide if all elements (e.g. style, script) must be children of
459
- * document.body. By default, browsers might move them to document.head */
460
-
461
- var FORCE_BODY = false;
462
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
463
- * string (or a TrustedHTML object if Trusted Types are supported).
464
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
465
- */
466
-
467
- var RETURN_DOM = false;
468
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
469
- * string (or a TrustedHTML object if Trusted Types are supported) */
470
-
471
- var RETURN_DOM_FRAGMENT = false;
472
- /* Try to return a Trusted Type object instead of a string, return a string in
473
- * case Trusted Types are not supported */
474
-
475
- var RETURN_TRUSTED_TYPE = false;
476
- /* Output should be free from DOM clobbering attacks? */
477
-
478
- var SANITIZE_DOM = true;
479
- /* Keep element content when removing element? */
480
-
481
- var KEEP_CONTENT = true;
482
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
483
- * of importing it into a new Document and returning a sanitized copy */
484
-
485
- var IN_PLACE = false;
486
- /* Allow usage of profiles like html, svg and mathMl */
487
-
488
- var USE_PROFILES = {};
489
- /* Tags to ignore content of when KEEP_CONTENT is true */
490
-
491
- var FORBID_CONTENTS = null;
492
- var DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
493
- /* Tags that are safe for data: URIs */
494
-
495
- var DATA_URI_TAGS = null;
496
- var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
497
- /* Attributes safe for values like "javascript:" */
498
-
499
- var URI_SAFE_ATTRIBUTES = null;
500
- var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
501
- var MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
502
- var SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
503
- var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
504
- /* Document namespace */
505
-
506
- var NAMESPACE = HTML_NAMESPACE;
507
- var IS_EMPTY_INPUT = false;
508
- /* Parsing of strict XHTML documents */
509
-
510
- var PARSER_MEDIA_TYPE;
511
- var SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
512
- var DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
513
- var transformCaseFunc;
514
- /* Keep a reference to config to pass to hooks */
515
-
516
- var CONFIG = null;
517
- /* Ideally, do not touch anything below this line */
518
-
519
- /* ______________________________________________ */
520
-
521
- var formElement = document.createElement('form');
522
-
523
- var isRegexOrFunction = function isRegexOrFunction(testValue) {
524
- return testValue instanceof RegExp || testValue instanceof Function;
525
- };
526
- /**
527
- * _parseConfig
528
- *
529
- * @param {Object} cfg optional config literal
530
- */
531
- // eslint-disable-next-line complexity
532
-
533
-
534
- var _parseConfig = function _parseConfig(cfg) {
535
- if (CONFIG && CONFIG === cfg) {
536
- return;
537
- }
538
- /* Shield configuration object from tampering */
539
-
540
-
541
- if (!cfg || _typeof(cfg) !== 'object') {
542
- cfg = {};
543
- }
544
- /* Shield configuration object from prototype pollution */
545
-
546
-
547
- cfg = clone(cfg);
548
- /* Set configuration parameters */
549
-
550
- ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
551
- ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
552
- URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
553
- DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
554
- FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS) : DEFAULT_FORBID_CONTENTS;
555
- FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
556
- FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
557
- USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
558
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
559
-
560
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
561
-
562
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
563
-
564
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
565
-
566
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
567
-
568
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
569
-
570
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
571
-
572
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
573
-
574
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
575
-
576
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
577
-
578
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
579
-
580
- IN_PLACE = cfg.IN_PLACE || false; // Default false
581
-
582
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$1;
583
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
584
-
585
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
586
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
587
- }
588
-
589
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
590
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
591
- }
592
-
593
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
594
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
595
- }
596
-
597
- PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
598
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
599
-
600
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? function (x) {
601
- return x;
602
- } : stringToLowerCase;
603
-
604
- if (SAFE_FOR_TEMPLATES) {
605
- ALLOW_DATA_ATTR = false;
606
- }
607
-
608
- if (RETURN_DOM_FRAGMENT) {
609
- RETURN_DOM = true;
610
- }
611
- /* Parse profile info */
612
-
613
-
614
- if (USE_PROFILES) {
615
- ALLOWED_TAGS = addToSet({}, _toConsumableArray(text));
616
- ALLOWED_ATTR = [];
617
-
618
- if (USE_PROFILES.html === true) {
619
- addToSet(ALLOWED_TAGS, html$1);
620
- addToSet(ALLOWED_ATTR, html);
621
- }
622
-
623
- if (USE_PROFILES.svg === true) {
624
- addToSet(ALLOWED_TAGS, svg$1);
625
- addToSet(ALLOWED_ATTR, svg);
626
- addToSet(ALLOWED_ATTR, xml);
627
- }
628
-
629
- if (USE_PROFILES.svgFilters === true) {
630
- addToSet(ALLOWED_TAGS, svgFilters);
631
- addToSet(ALLOWED_ATTR, svg);
632
- addToSet(ALLOWED_ATTR, xml);
633
- }
634
-
635
- if (USE_PROFILES.mathMl === true) {
636
- addToSet(ALLOWED_TAGS, mathMl$1);
637
- addToSet(ALLOWED_ATTR, mathMl);
638
- addToSet(ALLOWED_ATTR, xml);
639
- }
640
- }
641
- /* Merge configuration parameters */
642
-
643
-
644
- if (cfg.ADD_TAGS) {
645
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
646
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
647
- }
648
-
649
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
650
- }
651
-
652
- if (cfg.ADD_ATTR) {
653
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
654
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
655
- }
656
-
657
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
658
- }
659
-
660
- if (cfg.ADD_URI_SAFE_ATTR) {
661
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
662
- }
663
-
664
- if (cfg.FORBID_CONTENTS) {
665
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
666
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
667
- }
668
-
669
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS);
670
- }
671
- /* Add #text in case KEEP_CONTENT is set to true */
672
-
673
-
674
- if (KEEP_CONTENT) {
675
- ALLOWED_TAGS['#text'] = true;
676
- }
677
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
678
-
679
-
680
- if (WHOLE_DOCUMENT) {
681
- addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
682
- }
683
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
684
-
685
-
686
- if (ALLOWED_TAGS.table) {
687
- addToSet(ALLOWED_TAGS, ['tbody']);
688
- delete FORBID_TAGS.tbody;
689
- } // Prevent further manipulation of configuration.
690
- // Not available in IE8, Safari 5, etc.
691
-
692
-
693
- if (freeze) {
694
- freeze(cfg);
695
- }
696
-
697
- CONFIG = cfg;
698
- };
699
-
700
- var MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
701
- var HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
702
- // namespace. We need to specify them explicitly
703
- // so that they don't get erroneously deleted from
704
- // HTML namespace.
705
-
706
- var COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
707
- /* Keep track of all possible SVG and MathML tags
708
- * so that we can perform the namespace checks
709
- * correctly. */
710
-
711
- var ALL_SVG_TAGS = addToSet({}, svg$1);
712
- addToSet(ALL_SVG_TAGS, svgFilters);
713
- addToSet(ALL_SVG_TAGS, svgDisallowed);
714
- var ALL_MATHML_TAGS = addToSet({}, mathMl$1);
715
- addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
716
- /**
717
- *
718
- *
719
- * @param {Element} element a DOM element whose namespace is being checked
720
- * @returns {boolean} Return false if the element has a
721
- * namespace that a spec-compliant parser would never
722
- * return. Return true otherwise.
723
- */
724
-
725
- var _checkValidNamespace = function _checkValidNamespace(element) {
726
- var parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
727
- // can be null. We just simulate parent in this case.
728
-
729
- if (!parent || !parent.tagName) {
730
- parent = {
731
- namespaceURI: HTML_NAMESPACE,
732
- tagName: 'template'
733
- };
734
- }
735
-
736
- var tagName = stringToLowerCase(element.tagName);
737
- var parentTagName = stringToLowerCase(parent.tagName);
738
-
739
- if (element.namespaceURI === SVG_NAMESPACE) {
740
- // The only way to switch from HTML namespace to SVG
741
- // is via <svg>. If it happens via any other tag, then
742
- // it should be killed.
743
- if (parent.namespaceURI === HTML_NAMESPACE) {
744
- return tagName === 'svg';
745
- } // The only way to switch from MathML to SVG is via
746
- // svg if parent is either <annotation-xml> or MathML
747
- // text integration points.
748
-
749
-
750
- if (parent.namespaceURI === MATHML_NAMESPACE) {
751
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
752
- } // We only allow elements that are defined in SVG
753
- // spec. All others are disallowed in SVG namespace.
754
-
755
-
756
- return Boolean(ALL_SVG_TAGS[tagName]);
757
- }
758
-
759
- if (element.namespaceURI === MATHML_NAMESPACE) {
760
- // The only way to switch from HTML namespace to MathML
761
- // is via <math>. If it happens via any other tag, then
762
- // it should be killed.
763
- if (parent.namespaceURI === HTML_NAMESPACE) {
764
- return tagName === 'math';
765
- } // The only way to switch from SVG to MathML is via
766
- // <math> and HTML integration points
767
-
768
-
769
- if (parent.namespaceURI === SVG_NAMESPACE) {
770
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
771
- } // We only allow elements that are defined in MathML
772
- // spec. All others are disallowed in MathML namespace.
773
-
774
-
775
- return Boolean(ALL_MATHML_TAGS[tagName]);
776
- }
777
-
778
- if (element.namespaceURI === HTML_NAMESPACE) {
779
- // The only way to switch from SVG to HTML is via
780
- // HTML integration points, and from MathML to HTML
781
- // is via MathML text integration points
782
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
783
- return false;
784
- }
785
-
786
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
787
- return false;
788
- } // We disallow tags that are specific for MathML
789
- // or SVG and should never appear in HTML namespace
790
-
791
-
792
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
793
- } // The code should never reach this place (this means
794
- // that the element somehow got namespace that is not
795
- // HTML, SVG or MathML). Return false just in case.
796
-
797
-
798
- return false;
799
- };
800
- /**
801
- * _forceRemove
802
- *
803
- * @param {Node} node a DOM node
804
- */
805
-
806
-
807
- var _forceRemove = function _forceRemove(node) {
808
- arrayPush(DOMPurify.removed, {
809
- element: node
810
- });
811
-
812
- try {
813
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
814
- node.parentNode.removeChild(node);
815
- } catch (_) {
816
- try {
817
- node.outerHTML = emptyHTML;
818
- } catch (_) {
819
- node.remove();
820
- }
821
- }
822
- };
823
- /**
824
- * _removeAttribute
825
- *
826
- * @param {String} name an Attribute name
827
- * @param {Node} node a DOM node
828
- */
829
-
830
-
831
- var _removeAttribute = function _removeAttribute(name, node) {
832
- try {
833
- arrayPush(DOMPurify.removed, {
834
- attribute: node.getAttributeNode(name),
835
- from: node
836
- });
837
- } catch (_) {
838
- arrayPush(DOMPurify.removed, {
839
- attribute: null,
840
- from: node
841
- });
842
- }
843
-
844
- node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
845
-
846
- if (name === 'is' && !ALLOWED_ATTR[name]) {
847
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
848
- try {
849
- _forceRemove(node);
850
- } catch (_) {}
851
- } else {
852
- try {
853
- node.setAttribute(name, '');
854
- } catch (_) {}
855
- }
856
- }
857
- };
858
- /**
859
- * _initDocument
860
- *
861
- * @param {String} dirty a string of dirty markup
862
- * @return {Document} a DOM, filled with the dirty markup
863
- */
864
-
865
-
866
- var _initDocument = function _initDocument(dirty) {
867
- /* Create a HTML document */
868
- var doc;
869
- var leadingWhitespace;
870
-
871
- if (FORCE_BODY) {
872
- dirty = '<remove></remove>' + dirty;
873
- } else {
874
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
875
- var matches = stringMatch(dirty, /^[\r\n\t ]+/);
876
- leadingWhitespace = matches && matches[0];
877
- }
878
-
879
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml') {
880
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
881
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
882
- }
883
-
884
- var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
885
- /*
886
- * Use the DOMParser API by default, fallback later if needs be
887
- * DOMParser not work for svg when has multiple root element.
888
- */
889
-
890
- if (NAMESPACE === HTML_NAMESPACE) {
891
- try {
892
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
893
- } catch (_) {}
894
- }
895
- /* Use createHTMLDocument in case DOMParser is not available */
896
-
897
-
898
- if (!doc || !doc.documentElement) {
899
- doc = implementation.createDocument(NAMESPACE, 'template', null);
900
-
901
- try {
902
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? '' : dirtyPayload;
903
- } catch (_) {// Syntax error if dirtyPayload is invalid xml
904
- }
905
- }
906
-
907
- var body = doc.body || doc.documentElement;
908
-
909
- if (dirty && leadingWhitespace) {
910
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
911
- }
912
- /* Work on whole document or just its body */
913
-
914
-
915
- if (NAMESPACE === HTML_NAMESPACE) {
916
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
917
- }
918
-
919
- return WHOLE_DOCUMENT ? doc.documentElement : body;
920
- };
921
- /**
922
- * _createIterator
923
- *
924
- * @param {Document} root document/fragment to create iterator for
925
- * @return {Iterator} iterator instance
926
- */
927
-
928
-
929
- var _createIterator = function _createIterator(root) {
930
- return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
931
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
932
- };
933
- /**
934
- * _isClobbered
935
- *
936
- * @param {Node} elm element to check for clobbering attacks
937
- * @return {Boolean} true if clobbered, false if safe
938
- */
939
-
940
-
941
- var _isClobbered = function _isClobbered(elm) {
942
- 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');
943
- };
944
- /**
945
- * _isNode
946
- *
947
- * @param {Node} obj object to check whether it's a DOM node
948
- * @return {Boolean} true is object is a DOM node
949
- */
950
-
951
-
952
- var _isNode = function _isNode(object) {
953
- return _typeof(Node) === 'object' ? object instanceof Node : object && _typeof(object) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
954
- };
955
- /**
956
- * _executeHook
957
- * Execute user configurable hooks
958
- *
959
- * @param {String} entryPoint Name of the hook's entry point
960
- * @param {Node} currentNode node to work on with the hook
961
- * @param {Object} data additional hook parameters
962
- */
963
-
964
-
965
- var _executeHook = function _executeHook(entryPoint, currentNode, data) {
966
- if (!hooks[entryPoint]) {
967
- return;
968
- }
969
-
970
- arrayForEach(hooks[entryPoint], function (hook) {
971
- hook.call(DOMPurify, currentNode, data, CONFIG);
972
- });
973
- };
974
- /**
975
- * _sanitizeElements
976
- *
977
- * @protect nodeName
978
- * @protect textContent
979
- * @protect removeChild
980
- *
981
- * @param {Node} currentNode to check for permission to exist
982
- * @return {Boolean} true if node was killed, false if left alive
983
- */
984
-
985
-
986
- var _sanitizeElements = function _sanitizeElements(currentNode) {
987
- var content;
988
- /* Execute a hook if present */
989
-
990
- _executeHook('beforeSanitizeElements', currentNode, null);
991
- /* Check if element is clobbered or can clobber */
992
-
993
-
994
- if (_isClobbered(currentNode)) {
995
- _forceRemove(currentNode);
996
-
997
- return true;
998
- }
999
- /* Check if tagname contains Unicode */
1000
-
1001
-
1002
- if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
1003
- _forceRemove(currentNode);
1004
-
1005
- return true;
1006
- }
1007
- /* Now let's check the element's type and name */
1008
-
1009
-
1010
- var tagName = transformCaseFunc(currentNode.nodeName);
1011
- /* Execute a hook if present */
1012
-
1013
- _executeHook('uponSanitizeElement', currentNode, {
1014
- tagName: tagName,
1015
- allowedTags: ALLOWED_TAGS
1016
- });
1017
- /* Detect mXSS attempts abusing namespace confusion */
1018
-
1019
-
1020
- if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1021
- _forceRemove(currentNode);
1022
-
1023
- return true;
1024
- }
1025
- /* Mitigate a problem with templates inside select */
1026
-
1027
-
1028
- if (tagName === 'select' && regExpTest(/<template/i, currentNode.innerHTML)) {
1029
- _forceRemove(currentNode);
1030
-
1031
- return true;
1032
- }
1033
- /* Remove element if anything forbids its presence */
1034
-
1035
-
1036
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1037
- /* Check if we have a custom element to handle */
1038
- if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1039
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1040
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1041
- }
1042
- /* Keep content except for bad-listed elements */
1043
-
1044
-
1045
- if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1046
- var parentNode = getParentNode(currentNode) || currentNode.parentNode;
1047
- var childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1048
-
1049
- if (childNodes && parentNode) {
1050
- var childCount = childNodes.length;
1051
-
1052
- for (var i = childCount - 1; i >= 0; --i) {
1053
- parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1054
- }
1055
- }
1056
- }
1057
-
1058
- _forceRemove(currentNode);
1059
-
1060
- return true;
1061
- }
1062
- /* Check whether element has a valid namespace */
1063
-
1064
-
1065
- if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1066
- _forceRemove(currentNode);
1067
-
1068
- return true;
1069
- }
1070
-
1071
- if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1072
- _forceRemove(currentNode);
1073
-
1074
- return true;
1075
- }
1076
- /* Sanitize element content to be template-safe */
1077
-
1078
-
1079
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1080
- /* Get the element's text content */
1081
- content = currentNode.textContent;
1082
- content = stringReplace(content, MUSTACHE_EXPR$1, ' ');
1083
- content = stringReplace(content, ERB_EXPR$1, ' ');
1084
-
1085
- if (currentNode.textContent !== content) {
1086
- arrayPush(DOMPurify.removed, {
1087
- element: currentNode.cloneNode()
1088
- });
1089
- currentNode.textContent = content;
1090
- }
1091
- }
1092
- /* Execute a hook if present */
1093
-
1094
-
1095
- _executeHook('afterSanitizeElements', currentNode, null);
1096
-
1097
- return false;
1098
- };
1099
- /**
1100
- * _isValidAttribute
1101
- *
1102
- * @param {string} lcTag Lowercase tag name of containing element.
1103
- * @param {string} lcName Lowercase attribute name.
1104
- * @param {string} value Attribute value.
1105
- * @return {Boolean} Returns true if `value` is valid, otherwise false.
1106
- */
1107
- // eslint-disable-next-line complexity
1108
-
1109
-
1110
- var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1111
- /* Make sure attribute cannot clobber */
1112
- if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1113
- return false;
1114
- }
1115
- /* Allow valid data-* attributes: At least one character after "-"
1116
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1117
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1118
- We don't need to check the value; it's always URI safe. */
1119
-
1120
-
1121
- if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1122
- if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1123
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1124
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1125
- _basicCustomElementTest(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
1126
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1127
- 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))) ; else {
1128
- return false;
1129
- }
1130
- /* Check value is safe. First, is attr inert? If so, is safe */
1131
-
1132
- } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ''))) ; else if (!value) ; else {
1133
- return false;
1134
- }
1135
-
1136
- return true;
1137
- };
1138
- /**
1139
- * _basicCustomElementCheck
1140
- * checks if at least one dash is included in tagName, and it's not the first char
1141
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1142
- * @param {string} tagName name of the tag of the node to sanitize
1143
- */
1144
-
1145
-
1146
- var _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1147
- return tagName.indexOf('-') > 0;
1148
- };
1149
- /**
1150
- * _sanitizeAttributes
1151
- *
1152
- * @protect attributes
1153
- * @protect nodeName
1154
- * @protect removeAttribute
1155
- * @protect setAttribute
1156
- *
1157
- * @param {Node} currentNode to sanitize
1158
- */
1159
-
1160
-
1161
- var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1162
- var attr;
1163
- var value;
1164
- var lcName;
1165
- var l;
1166
- /* Execute a hook if present */
1167
-
1168
- _executeHook('beforeSanitizeAttributes', currentNode, null);
1169
-
1170
- var attributes = currentNode.attributes;
1171
- /* Check if we have attributes; if not we might have a text node */
1172
-
1173
- if (!attributes) {
1174
- return;
1175
- }
1176
-
1177
- var hookEvent = {
1178
- attrName: '',
1179
- attrValue: '',
1180
- keepAttr: true,
1181
- allowedAttributes: ALLOWED_ATTR
1182
- };
1183
- l = attributes.length;
1184
- /* Go backwards over all attributes; safely remove bad ones */
1185
-
1186
- while (l--) {
1187
- attr = attributes[l];
1188
- var _attr = attr,
1189
- name = _attr.name,
1190
- namespaceURI = _attr.namespaceURI;
1191
- value = name === 'value' ? attr.value : stringTrim(attr.value);
1192
- lcName = transformCaseFunc(name);
1193
- /* Execute a hook if present */
1194
-
1195
- hookEvent.attrName = lcName;
1196
- hookEvent.attrValue = value;
1197
- hookEvent.keepAttr = true;
1198
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1199
-
1200
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1201
-
1202
- value = hookEvent.attrValue;
1203
- /* Did the hooks approve of the attribute? */
1204
-
1205
- if (hookEvent.forceKeepAttr) {
1206
- continue;
1207
- }
1208
- /* Remove attribute */
1209
-
1210
-
1211
- _removeAttribute(name, currentNode);
1212
- /* Did the hooks approve of the attribute? */
1213
-
1214
-
1215
- if (!hookEvent.keepAttr) {
1216
- continue;
1217
- }
1218
- /* Work around a security issue in jQuery 3.0 */
1219
-
1220
-
1221
- if (regExpTest(/\/>/i, value)) {
1222
- _removeAttribute(name, currentNode);
1223
-
1224
- continue;
1225
- }
1226
- /* Sanitize attribute content to be template-safe */
1227
-
1228
-
1229
- if (SAFE_FOR_TEMPLATES) {
1230
- value = stringReplace(value, MUSTACHE_EXPR$1, ' ');
1231
- value = stringReplace(value, ERB_EXPR$1, ' ');
1232
- }
1233
- /* Is `value` valid for this attribute? */
1234
-
1235
-
1236
- var lcTag = transformCaseFunc(currentNode.nodeName);
1237
-
1238
- if (!_isValidAttribute(lcTag, lcName, value)) {
1239
- continue;
1240
- }
1241
- /* Handle invalid data-* attribute set by try-catching it */
1242
-
1243
-
1244
- try {
1245
- if (namespaceURI) {
1246
- currentNode.setAttributeNS(namespaceURI, name, value);
1247
- } else {
1248
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1249
- currentNode.setAttribute(name, value);
1250
- }
1251
-
1252
- arrayPop(DOMPurify.removed);
1253
- } catch (_) {}
1254
- }
1255
- /* Execute a hook if present */
1256
-
1257
-
1258
- _executeHook('afterSanitizeAttributes', currentNode, null);
1259
- };
1260
- /**
1261
- * _sanitizeShadowDOM
1262
- *
1263
- * @param {DocumentFragment} fragment to iterate over recursively
1264
- */
1265
-
1266
-
1267
- var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1268
- var shadowNode;
1269
-
1270
- var shadowIterator = _createIterator(fragment);
1271
- /* Execute a hook if present */
1272
-
1273
-
1274
- _executeHook('beforeSanitizeShadowDOM', fragment, null);
1275
-
1276
- while (shadowNode = shadowIterator.nextNode()) {
1277
- /* Execute a hook if present */
1278
- _executeHook('uponSanitizeShadowNode', shadowNode, null);
1279
- /* Sanitize tags and elements */
1280
-
1281
-
1282
- if (_sanitizeElements(shadowNode)) {
1283
- continue;
1284
- }
1285
- /* Deep shadow DOM detected */
1286
-
1287
-
1288
- if (shadowNode.content instanceof DocumentFragment) {
1289
- _sanitizeShadowDOM(shadowNode.content);
1290
- }
1291
- /* Check attributes, sanitize if necessary */
1292
-
1293
-
1294
- _sanitizeAttributes(shadowNode);
1295
- }
1296
- /* Execute a hook if present */
1297
-
1298
-
1299
- _executeHook('afterSanitizeShadowDOM', fragment, null);
1300
- };
1301
- /**
1302
- * Sanitize
1303
- * Public method providing core sanitation functionality
1304
- *
1305
- * @param {String|Node} dirty string or DOM node
1306
- * @param {Object} configuration object
1307
- */
1308
- // eslint-disable-next-line complexity
1309
-
1310
-
1311
- DOMPurify.sanitize = function (dirty, cfg) {
1312
- var body;
1313
- var importedNode;
1314
- var currentNode;
1315
- var oldNode;
1316
- var returnNode;
1317
- /* Make sure we have a string to sanitize.
1318
- DO NOT return early, as this will return the wrong type if
1319
- the user has requested a DOM object rather than a string */
1320
-
1321
- IS_EMPTY_INPUT = !dirty;
1322
-
1323
- if (IS_EMPTY_INPUT) {
1324
- dirty = '<!-->';
1325
- }
1326
- /* Stringify, in case dirty is an object */
1327
-
1328
-
1329
- if (typeof dirty !== 'string' && !_isNode(dirty)) {
1330
- // eslint-disable-next-line no-negated-condition
1331
- if (typeof dirty.toString !== 'function') {
1332
- throw typeErrorCreate('toString is not a function');
1333
- } else {
1334
- dirty = dirty.toString();
1335
-
1336
- if (typeof dirty !== 'string') {
1337
- throw typeErrorCreate('dirty is not a string, aborting');
1338
- }
1339
- }
1340
- }
1341
- /* Check we can run. Otherwise fall back or ignore */
1342
-
1343
-
1344
- if (!DOMPurify.isSupported) {
1345
- if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
1346
- if (typeof dirty === 'string') {
1347
- return window.toStaticHTML(dirty);
1348
- }
1349
-
1350
- if (_isNode(dirty)) {
1351
- return window.toStaticHTML(dirty.outerHTML);
1352
- }
1353
- }
1354
-
1355
- return dirty;
1356
- }
1357
- /* Assign config vars */
1358
-
1359
-
1360
- if (!SET_CONFIG) {
1361
- _parseConfig(cfg);
1362
- }
1363
- /* Clean up removed elements */
1364
-
1365
-
1366
- DOMPurify.removed = [];
1367
- /* Check if dirty is correctly typed for IN_PLACE */
1368
-
1369
- if (typeof dirty === 'string') {
1370
- IN_PLACE = false;
1371
- }
1372
-
1373
- if (IN_PLACE) {
1374
- /* Do some early pre-sanitization to avoid unsafe root nodes */
1375
- if (dirty.nodeName) {
1376
- var tagName = transformCaseFunc(dirty.nodeName);
1377
-
1378
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1379
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1380
- }
1381
- }
1382
- } else if (dirty instanceof Node) {
1383
- /* If dirty is a DOM element, append to an empty document to avoid
1384
- elements being stripped by the parser */
1385
- body = _initDocument('<!---->');
1386
- importedNode = body.ownerDocument.importNode(dirty, true);
1387
-
1388
- if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1389
- /* Node is already a body, use as is */
1390
- body = importedNode;
1391
- } else if (importedNode.nodeName === 'HTML') {
1392
- body = importedNode;
1393
- } else {
1394
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1395
- body.appendChild(importedNode);
1396
- }
1397
- } else {
1398
- /* Exit directly if we have nothing to do */
1399
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1400
- dirty.indexOf('<') === -1) {
1401
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1402
- }
1403
- /* Initialize the document to work on */
1404
-
1405
-
1406
- body = _initDocument(dirty);
1407
- /* Check we have a DOM node from the data */
1408
-
1409
- if (!body) {
1410
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1411
- }
1412
- }
1413
- /* Remove first element node (ours) if FORCE_BODY is set */
1414
-
1415
-
1416
- if (body && FORCE_BODY) {
1417
- _forceRemove(body.firstChild);
1418
- }
1419
- /* Get node iterator */
1420
-
1421
-
1422
- var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1423
- /* Now start iterating over the created document */
1424
-
1425
-
1426
- while (currentNode = nodeIterator.nextNode()) {
1427
- /* Fix IE's strange behavior with manipulated textNodes #89 */
1428
- if (currentNode.nodeType === 3 && currentNode === oldNode) {
1429
- continue;
1430
- }
1431
- /* Sanitize tags and elements */
1432
-
1433
-
1434
- if (_sanitizeElements(currentNode)) {
1435
- continue;
1436
- }
1437
- /* Shadow DOM detected, sanitize it */
1438
-
1439
-
1440
- if (currentNode.content instanceof DocumentFragment) {
1441
- _sanitizeShadowDOM(currentNode.content);
1442
- }
1443
- /* Check attributes, sanitize if necessary */
1444
-
1445
-
1446
- _sanitizeAttributes(currentNode);
1447
-
1448
- oldNode = currentNode;
1449
- }
1450
-
1451
- oldNode = null;
1452
- /* If we sanitized `dirty` in-place, return it. */
1453
-
1454
- if (IN_PLACE) {
1455
- return dirty;
1456
- }
1457
- /* Return sanitized string or DOM */
1458
-
1459
-
1460
- if (RETURN_DOM) {
1461
- if (RETURN_DOM_FRAGMENT) {
1462
- returnNode = createDocumentFragment.call(body.ownerDocument);
1463
-
1464
- while (body.firstChild) {
1465
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1466
- returnNode.appendChild(body.firstChild);
1467
- }
1468
- } else {
1469
- returnNode = body;
1470
- }
1471
-
1472
- if (ALLOWED_ATTR.shadowroot) {
1473
- /*
1474
- AdoptNode() is not used because internal state is not reset
1475
- (e.g. the past names map of a HTMLFormElement), this is safe
1476
- in theory but we would rather not risk another attack vector.
1477
- The state that is cloned by importNode() is explicitly defined
1478
- by the specs.
1479
- */
1480
- returnNode = importNode.call(originalDocument, returnNode, true);
1481
- }
1482
-
1483
- return returnNode;
1484
- }
1485
-
1486
- var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1487
- /* Serialize doctype if allowed */
1488
-
1489
- if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1490
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1491
- }
1492
- /* Sanitize final string template-safe */
1493
-
1494
-
1495
- if (SAFE_FOR_TEMPLATES) {
1496
- serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$1, ' ');
1497
- serializedHTML = stringReplace(serializedHTML, ERB_EXPR$1, ' ');
1498
- }
1499
-
1500
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1501
- };
1502
- /**
1503
- * Public method to set the configuration once
1504
- * setConfig
1505
- *
1506
- * @param {Object} cfg configuration object
1507
- */
1508
-
1509
-
1510
- DOMPurify.setConfig = function (cfg) {
1511
- _parseConfig(cfg);
1512
-
1513
- SET_CONFIG = true;
1514
- };
1515
- /**
1516
- * Public method to remove the configuration
1517
- * clearConfig
1518
- *
1519
- */
1520
-
1521
-
1522
- DOMPurify.clearConfig = function () {
1523
- CONFIG = null;
1524
- SET_CONFIG = false;
1525
- };
1526
- /**
1527
- * Public method to check if an attribute value is valid.
1528
- * Uses last set config, if any. Otherwise, uses config defaults.
1529
- * isValidAttribute
1530
- *
1531
- * @param {string} tag Tag name of containing element.
1532
- * @param {string} attr Attribute name.
1533
- * @param {string} value Attribute value.
1534
- * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1535
- */
1536
-
1537
-
1538
- DOMPurify.isValidAttribute = function (tag, attr, value) {
1539
- /* Initialize shared config vars if necessary. */
1540
- if (!CONFIG) {
1541
- _parseConfig({});
1542
- }
1543
-
1544
- var lcTag = transformCaseFunc(tag);
1545
- var lcName = transformCaseFunc(attr);
1546
- return _isValidAttribute(lcTag, lcName, value);
1547
- };
1548
- /**
1549
- * AddHook
1550
- * Public method to add DOMPurify hooks
1551
- *
1552
- * @param {String} entryPoint entry point for the hook to add
1553
- * @param {Function} hookFunction function to execute
1554
- */
1555
-
1556
-
1557
- DOMPurify.addHook = function (entryPoint, hookFunction) {
1558
- if (typeof hookFunction !== 'function') {
1559
- return;
1560
- }
1561
-
1562
- hooks[entryPoint] = hooks[entryPoint] || [];
1563
- arrayPush(hooks[entryPoint], hookFunction);
1564
- };
1565
- /**
1566
- * RemoveHook
1567
- * Public method to remove a DOMPurify hook at a given entryPoint
1568
- * (pops it from the stack of hooks if more are present)
1569
- *
1570
- * @param {String} entryPoint entry point for the hook to remove
1571
- * @return {Function} removed(popped) hook
1572
- */
1573
-
1574
-
1575
- DOMPurify.removeHook = function (entryPoint) {
1576
- if (hooks[entryPoint]) {
1577
- return arrayPop(hooks[entryPoint]);
1578
- }
1579
- };
1580
- /**
1581
- * RemoveHooks
1582
- * Public method to remove all DOMPurify hooks at a given entryPoint
1583
- *
1584
- * @param {String} entryPoint entry point for the hooks to remove
1585
- */
1586
-
1587
-
1588
- DOMPurify.removeHooks = function (entryPoint) {
1589
- if (hooks[entryPoint]) {
1590
- hooks[entryPoint] = [];
1591
- }
1592
- };
1593
- /**
1594
- * RemoveAllHooks
1595
- * Public method to remove all DOMPurify hooks
1596
- *
1597
- */
1598
-
1599
-
1600
- DOMPurify.removeAllHooks = function () {
1601
- hooks = {};
1602
- };
1603
-
1604
- return DOMPurify;
1605
- }
1606
-
1607
- var purify = createDOMPurify();
1608
-
1609
- export default purify;