1 |
|
2 |
|
3 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
4 |
|
5 | var hasOwnProperty = Object.hasOwnProperty,
|
6 | setPrototypeOf = Object.setPrototypeOf,
|
7 | isFrozen = Object.isFrozen,
|
8 | objectKeys = Object.keys;
|
9 | var freeze = Object.freeze,
|
10 | seal = Object.seal;
|
11 |
|
12 | var _ref = typeof Reflect !== 'undefined' && Reflect,
|
13 | apply = _ref.apply,
|
14 | construct = _ref.construct;
|
15 |
|
16 | if (!apply) {
|
17 | apply = function apply(fun, thisValue, args) {
|
18 | return fun.apply(thisValue, args);
|
19 | };
|
20 | }
|
21 |
|
22 | if (!freeze) {
|
23 | freeze = function freeze(x) {
|
24 | return x;
|
25 | };
|
26 | }
|
27 |
|
28 | if (!seal) {
|
29 | seal = function seal(x) {
|
30 | return x;
|
31 | };
|
32 | }
|
33 |
|
34 | if (!construct) {
|
35 | construct = function construct(Func, args) {
|
36 | return new (Function.prototype.bind.apply(Func, [null].concat(_toConsumableArray(args))))();
|
37 | };
|
38 | }
|
39 |
|
40 | var arrayForEach = unapply(Array.prototype.forEach);
|
41 | var arrayIndexOf = unapply(Array.prototype.indexOf);
|
42 | var arrayJoin = unapply(Array.prototype.join);
|
43 | var arrayPop = unapply(Array.prototype.pop);
|
44 | var arrayPush = unapply(Array.prototype.push);
|
45 | var arraySlice = unapply(Array.prototype.slice);
|
46 |
|
47 | var stringToLowerCase = unapply(String.prototype.toLowerCase);
|
48 | var stringMatch = unapply(String.prototype.match);
|
49 | var stringReplace = unapply(String.prototype.replace);
|
50 | var stringIndexOf = unapply(String.prototype.indexOf);
|
51 | var stringTrim = unapply(String.prototype.trim);
|
52 |
|
53 | var regExpTest = unapply(RegExp.prototype.test);
|
54 | var regExpCreate = unconstruct(RegExp);
|
55 |
|
56 | var typeErrorCreate = unconstruct(TypeError);
|
57 |
|
58 | function unapply(func) {
|
59 | return function (thisArg) {
|
60 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
61 | args[_key - 1] = arguments[_key];
|
62 | }
|
63 |
|
64 | return apply(func, thisArg, args);
|
65 | };
|
66 | }
|
67 |
|
68 | function unconstruct(func) {
|
69 | return function () {
|
70 | for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
71 | args[_key2] = arguments[_key2];
|
72 | }
|
73 |
|
74 | return construct(func, args);
|
75 | };
|
76 | }
|
77 |
|
78 |
|
79 | function addToSet(set, array) {
|
80 | if (setPrototypeOf) {
|
81 |
|
82 |
|
83 |
|
84 | setPrototypeOf(set, null);
|
85 | }
|
86 |
|
87 | var l = array.length;
|
88 | while (l--) {
|
89 | var element = array[l];
|
90 | if (typeof element === 'string') {
|
91 | var lcElement = stringToLowerCase(element);
|
92 | if (lcElement !== element) {
|
93 |
|
94 | if (!isFrozen(array)) {
|
95 | array[l] = lcElement;
|
96 | }
|
97 |
|
98 | element = lcElement;
|
99 | }
|
100 | }
|
101 |
|
102 | set[element] = true;
|
103 | }
|
104 |
|
105 | return set;
|
106 | }
|
107 |
|
108 | /* Shallow clone an object */
|
109 | function clone(object) {
|
110 | var newObject = {};
|
111 |
|
112 | var property = void 0;
|
113 | for (property in object) {
|
114 | if (apply(hasOwnProperty, object, [property])) {
|
115 | newObject[property] = object[property];
|
116 | }
|
117 | }
|
118 |
|
119 | return newObject;
|
120 | }
|
121 |
|
122 | var html = 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', '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']);
|
123 |
|
124 |
|
125 | var svg = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'audio', 'canvas', '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', 'video', 'view', 'vkern']);
|
126 |
|
127 | var svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
|
128 |
|
129 | var mathMl = 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']);
|
130 |
|
131 | var text = freeze(['#text']);
|
132 |
|
133 | var html$1 = 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', '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']);
|
134 |
|
135 | var svg$1 = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', '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', 'tabindex', 'targetx', 'targety', 'transform', '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']);
|
136 |
|
137 | var mathMl$1 = 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']);
|
138 |
|
139 | var xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
|
140 |
|
141 |
|
142 | var MUSTACHE_EXPR = seal(/\{\{[\s\S]*|[\s\S]*\}\}/gm);
|
143 | var ERB_EXPR = seal(/<%[\s\S]*|[\s\S]*%>/gm);
|
144 | var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/);
|
145 | var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
|
146 | var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
|
147 | );
|
148 | var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
|
149 | var ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g
|
150 | );
|
151 |
|
152 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
153 |
|
154 | function _toConsumableArray$1(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
|
155 |
|
156 | var getGlobal = function getGlobal() {
|
157 | return typeof window === 'undefined' ? null : window;
|
158 | };
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | var _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, document) {
|
169 | if ((typeof trustedTypes === 'undefined' ? 'undefined' : _typeof(trustedTypes)) !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
|
170 | return null;
|
171 | }
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | var suffix = null;
|
177 | var ATTR_NAME = 'data-tt-policy-suffix';
|
178 | if (document.currentScript && document.currentScript.hasAttribute(ATTR_NAME)) {
|
179 | suffix = document.currentScript.getAttribute(ATTR_NAME);
|
180 | }
|
181 |
|
182 | var policyName = 'dompurify' + (suffix ? '#' + suffix : '');
|
183 |
|
184 | try {
|
185 | return trustedTypes.createPolicy(policyName, {
|
186 | createHTML: function createHTML(html$$1) {
|
187 | return html$$1;
|
188 | }
|
189 | });
|
190 | } catch (_) {
|
191 |
|
192 |
|
193 |
|
194 | console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
|
195 | return null;
|
196 | }
|
197 | };
|
198 |
|
199 | function createDOMPurify() {
|
200 | var window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
|
201 |
|
202 | var DOMPurify = function DOMPurify(root) {
|
203 | return createDOMPurify(root);
|
204 | };
|
205 |
|
206 | |
207 |
|
208 |
|
209 |
|
210 | DOMPurify.version = '2.0.12';
|
211 |
|
212 | |
213 |
|
214 |
|
215 |
|
216 | DOMPurify.removed = [];
|
217 |
|
218 | if (!window || !window.document || window.document.nodeType !== 9) {
|
219 |
|
220 |
|
221 | DOMPurify.isSupported = false;
|
222 |
|
223 | return DOMPurify;
|
224 | }
|
225 |
|
226 | var originalDocument = window.document;
|
227 | var removeTitle = false;
|
228 |
|
229 | var document = window.document;
|
230 | var DocumentFragment = window.DocumentFragment,
|
231 | HTMLTemplateElement = window.HTMLTemplateElement,
|
232 | Node = window.Node,
|
233 | NodeFilter = window.NodeFilter,
|
234 | _window$NamedNodeMap = window.NamedNodeMap,
|
235 | NamedNodeMap = _window$NamedNodeMap === undefined ? window.NamedNodeMap || window.MozNamedAttrMap : _window$NamedNodeMap,
|
236 | Text = window.Text,
|
237 | Comment = window.Comment,
|
238 | DOMParser = window.DOMParser,
|
239 | trustedTypes = window.trustedTypes;
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | if (typeof HTMLTemplateElement === 'function') {
|
249 | var template = document.createElement('template');
|
250 | if (template.content && template.content.ownerDocument) {
|
251 | document = template.content.ownerDocument;
|
252 | }
|
253 | }
|
254 |
|
255 | var trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, originalDocument);
|
256 | var emptyHTML = trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML('') : '';
|
257 |
|
258 | var _document = document,
|
259 | implementation = _document.implementation,
|
260 | createNodeIterator = _document.createNodeIterator,
|
261 | getElementsByTagName = _document.getElementsByTagName,
|
262 | createDocumentFragment = _document.createDocumentFragment;
|
263 | var importNode = originalDocument.importNode;
|
264 |
|
265 |
|
266 | var hooks = {};
|
267 |
|
268 | |
269 |
|
270 |
|
271 | DOMPurify.isSupported = implementation && typeof implementation.createHTMLDocument !== 'undefined' && document.documentMode !== 9;
|
272 |
|
273 | var MUSTACHE_EXPR$$1 = MUSTACHE_EXPR,
|
274 | ERB_EXPR$$1 = ERB_EXPR,
|
275 | DATA_ATTR$$1 = DATA_ATTR,
|
276 | ARIA_ATTR$$1 = ARIA_ATTR,
|
277 | IS_SCRIPT_OR_DATA$$1 = IS_SCRIPT_OR_DATA,
|
278 | ATTR_WHITESPACE$$1 = ATTR_WHITESPACE;
|
279 | var IS_ALLOWED_URI$$1 = IS_ALLOWED_URI;
|
280 |
|
281 | |
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | var ALLOWED_TAGS = null;
|
289 | var DEFAULT_ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(html), _toConsumableArray$1(svg), _toConsumableArray$1(svgFilters), _toConsumableArray$1(mathMl), _toConsumableArray$1(text)));
|
290 |
|
291 |
|
292 | var ALLOWED_ATTR = null;
|
293 | var DEFAULT_ALLOWED_ATTR = addToSet({}, [].concat(_toConsumableArray$1(html$1), _toConsumableArray$1(svg$1), _toConsumableArray$1(mathMl$1), _toConsumableArray$1(xml)));
|
294 |
|
295 |
|
296 | var FORBID_TAGS = null;
|
297 |
|
298 |
|
299 | var FORBID_ATTR = null;
|
300 |
|
301 |
|
302 | var ALLOW_ARIA_ATTR = true;
|
303 |
|
304 |
|
305 | var ALLOW_DATA_ATTR = true;
|
306 |
|
307 |
|
308 | var ALLOW_UNKNOWN_PROTOCOLS = false;
|
309 |
|
310 |
|
311 | var SAFE_FOR_JQUERY = false;
|
312 |
|
313 | |
314 |
|
315 |
|
316 | var SAFE_FOR_TEMPLATES = false;
|
317 |
|
318 |
|
319 | var WHOLE_DOCUMENT = false;
|
320 |
|
321 |
|
322 | var SET_CONFIG = false;
|
323 |
|
324 | |
325 |
|
326 | var FORCE_BODY = false;
|
327 |
|
328 | |
329 |
|
330 |
|
331 |
|
332 | var RETURN_DOM = false;
|
333 |
|
334 | |
335 |
|
336 | var RETURN_DOM_FRAGMENT = false;
|
337 |
|
338 | |
339 |
|
340 |
|
341 |
|
342 | var RETURN_DOM_IMPORT = false;
|
343 |
|
344 | |
345 |
|
346 | var RETURN_TRUSTED_TYPE = false;
|
347 |
|
348 |
|
349 | var SANITIZE_DOM = true;
|
350 |
|
351 |
|
352 | var KEEP_CONTENT = true;
|
353 |
|
354 | |
355 |
|
356 | var IN_PLACE = false;
|
357 |
|
358 |
|
359 | var USE_PROFILES = {};
|
360 |
|
361 |
|
362 | var FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
|
363 |
|
364 |
|
365 | var DATA_URI_TAGS = null;
|
366 | var DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
|
367 |
|
368 |
|
369 | var URI_SAFE_ATTRIBUTES = null;
|
370 | var DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'summary', 'title', 'value', 'style', 'xmlns']);
|
371 |
|
372 |
|
373 | var CONFIG = null;
|
374 |
|
375 |
|
376 |
|
377 |
|
378 | var formElement = document.createElement('form');
|
379 |
|
380 | |
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 | var _parseConfig = function _parseConfig(cfg) {
|
387 | if (CONFIG && CONFIG === cfg) {
|
388 | return;
|
389 | }
|
390 |
|
391 |
|
392 | if (!cfg || (typeof cfg === 'undefined' ? 'undefined' : _typeof(cfg)) !== 'object') {
|
393 | cfg = {};
|
394 | }
|
395 |
|
396 |
|
397 | ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS) : DEFAULT_ALLOWED_TAGS;
|
398 | ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR) : DEFAULT_ALLOWED_ATTR;
|
399 | URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR) : DEFAULT_URI_SAFE_ATTRIBUTES;
|
400 | DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS) : DEFAULT_DATA_URI_TAGS;
|
401 | FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS) : {};
|
402 | FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR) : {};
|
403 | USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
|
404 | ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
|
405 | ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
|
406 | ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
|
407 | SAFE_FOR_JQUERY = cfg.SAFE_FOR_JQUERY || false;
|
408 | SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
|
409 | WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
|
410 | RETURN_DOM = cfg.RETURN_DOM || false;
|
411 | RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
|
412 | RETURN_DOM_IMPORT = cfg.RETURN_DOM_IMPORT || false;
|
413 | RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
|
414 | FORCE_BODY = cfg.FORCE_BODY || false;
|
415 | SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
|
416 | KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
|
417 | IN_PLACE = cfg.IN_PLACE || false;
|
418 | IS_ALLOWED_URI$$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI$$1;
|
419 | if (SAFE_FOR_TEMPLATES) {
|
420 | ALLOW_DATA_ATTR = false;
|
421 | }
|
422 |
|
423 | if (RETURN_DOM_FRAGMENT) {
|
424 | RETURN_DOM = true;
|
425 | }
|
426 |
|
427 |
|
428 | if (USE_PROFILES) {
|
429 | ALLOWED_TAGS = addToSet({}, [].concat(_toConsumableArray$1(text)));
|
430 | ALLOWED_ATTR = [];
|
431 | if (USE_PROFILES.html === true) {
|
432 | addToSet(ALLOWED_TAGS, html);
|
433 | addToSet(ALLOWED_ATTR, html$1);
|
434 | }
|
435 |
|
436 | if (USE_PROFILES.svg === true) {
|
437 | addToSet(ALLOWED_TAGS, svg);
|
438 | addToSet(ALLOWED_ATTR, svg$1);
|
439 | addToSet(ALLOWED_ATTR, xml);
|
440 | }
|
441 |
|
442 | if (USE_PROFILES.svgFilters === true) {
|
443 | addToSet(ALLOWED_TAGS, svgFilters);
|
444 | addToSet(ALLOWED_ATTR, svg$1);
|
445 | addToSet(ALLOWED_ATTR, xml);
|
446 | }
|
447 |
|
448 | if (USE_PROFILES.mathMl === true) {
|
449 | addToSet(ALLOWED_TAGS, mathMl);
|
450 | addToSet(ALLOWED_ATTR, mathMl$1);
|
451 | addToSet(ALLOWED_ATTR, xml);
|
452 | }
|
453 | }
|
454 |
|
455 |
|
456 | if (cfg.ADD_TAGS) {
|
457 | if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
|
458 | ALLOWED_TAGS = clone(ALLOWED_TAGS);
|
459 | }
|
460 |
|
461 | addToSet(ALLOWED_TAGS, cfg.ADD_TAGS);
|
462 | }
|
463 |
|
464 | if (cfg.ADD_ATTR) {
|
465 | if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
|
466 | ALLOWED_ATTR = clone(ALLOWED_ATTR);
|
467 | }
|
468 |
|
469 | addToSet(ALLOWED_ATTR, cfg.ADD_ATTR);
|
470 | }
|
471 |
|
472 | if (cfg.ADD_URI_SAFE_ATTR) {
|
473 | addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR);
|
474 | }
|
475 |
|
476 |
|
477 | if (KEEP_CONTENT) {
|
478 | ALLOWED_TAGS['#text'] = true;
|
479 | }
|
480 |
|
481 |
|
482 | if (WHOLE_DOCUMENT) {
|
483 | addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
|
484 | }
|
485 |
|
486 |
|
487 | if (ALLOWED_TAGS.table) {
|
488 | addToSet(ALLOWED_TAGS, ['tbody']);
|
489 | delete FORBID_TAGS.tbody;
|
490 | }
|
491 |
|
492 |
|
493 |
|
494 | if (freeze) {
|
495 | freeze(cfg);
|
496 | }
|
497 |
|
498 | CONFIG = cfg;
|
499 | };
|
500 |
|
501 | |
502 |
|
503 |
|
504 |
|
505 |
|
506 | var _forceRemove = function _forceRemove(node) {
|
507 | arrayPush(DOMPurify.removed, { element: node });
|
508 | try {
|
509 |
|
510 | node.parentNode.removeChild(node);
|
511 | } catch (_) {
|
512 | node.outerHTML = emptyHTML;
|
513 | }
|
514 | };
|
515 |
|
516 | |
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 | var _removeAttribute = function _removeAttribute(name, node) {
|
523 | try {
|
524 | arrayPush(DOMPurify.removed, {
|
525 | attribute: node.getAttributeNode(name),
|
526 | from: node
|
527 | });
|
528 | } catch (_) {
|
529 | arrayPush(DOMPurify.removed, {
|
530 | attribute: null,
|
531 | from: node
|
532 | });
|
533 | }
|
534 |
|
535 | node.removeAttribute(name);
|
536 | };
|
537 |
|
538 | |
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | var _initDocument = function _initDocument(dirty) {
|
545 |
|
546 | var doc = void 0;
|
547 | var leadingWhitespace = void 0;
|
548 |
|
549 | if (FORCE_BODY) {
|
550 | dirty = '<remove></remove>' + dirty;
|
551 | } else {
|
552 |
|
553 | var matches = stringMatch(dirty, /^[\r\n\t ]+/);
|
554 | leadingWhitespace = matches && matches[0];
|
555 | }
|
556 |
|
557 | var dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
558 |
|
559 | try {
|
560 | doc = new DOMParser().parseFromString(dirtyPayload, 'text/html');
|
561 | } catch (_) {}
|
562 |
|
563 |
|
564 | if (removeTitle) {
|
565 | addToSet(FORBID_TAGS, ['title']);
|
566 | }
|
567 |
|
568 |
|
569 | if (!doc || !doc.documentElement) {
|
570 | doc = implementation.createHTMLDocument('');
|
571 | var _doc = doc,
|
572 | body = _doc.body;
|
573 |
|
574 | body.parentNode.removeChild(body.parentNode.firstElementChild);
|
575 | body.outerHTML = dirtyPayload;
|
576 | }
|
577 |
|
578 | if (dirty && leadingWhitespace) {
|
579 | doc.body.insertBefore(document.createTextNode(leadingWhitespace), doc.body.childNodes[0] || null);
|
580 | }
|
581 |
|
582 |
|
583 | return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
|
584 | };
|
585 |
|
586 |
|
587 | if (DOMPurify.isSupported) {
|
588 | (function () {
|
589 | try {
|
590 | var doc = _initDocument('<x/><title></title><img>');
|
591 | if (regExpTest(/<\/title/, doc.querySelector('title').innerHTML)) {
|
592 | removeTitle = true;
|
593 | }
|
594 | } catch (_) {}
|
595 | })();
|
596 | }
|
597 |
|
598 | |
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 | var _createIterator = function _createIterator(root) {
|
605 | return createNodeIterator.call(root.ownerDocument || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, function () {
|
606 | return NodeFilter.FILTER_ACCEPT;
|
607 | }, false);
|
608 | };
|
609 |
|
610 | |
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 | var _isClobbered = function _isClobbered(elm) {
|
617 | if (elm instanceof Text || elm instanceof Comment) {
|
618 | return false;
|
619 | }
|
620 |
|
621 | if (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') {
|
622 | return true;
|
623 | }
|
624 |
|
625 | return false;
|
626 | };
|
627 |
|
628 | |
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 | var _isNode = function _isNode(object) {
|
635 | return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? object instanceof Node : object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
|
636 | };
|
637 |
|
638 | |
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 | var _executeHook = function _executeHook(entryPoint, currentNode, data) {
|
647 | if (!hooks[entryPoint]) {
|
648 | return;
|
649 | }
|
650 |
|
651 | arrayForEach(hooks[entryPoint], function (hook) {
|
652 | hook.call(DOMPurify, currentNode, data, CONFIG);
|
653 | });
|
654 | };
|
655 |
|
656 | |
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 | var _sanitizeElements = function _sanitizeElements(currentNode) {
|
668 | var content = void 0;
|
669 |
|
670 |
|
671 | _executeHook('beforeSanitizeElements', currentNode, null);
|
672 |
|
673 |
|
674 | if (_isClobbered(currentNode)) {
|
675 | _forceRemove(currentNode);
|
676 | return true;
|
677 | }
|
678 |
|
679 |
|
680 | var tagName = stringToLowerCase(currentNode.nodeName);
|
681 |
|
682 |
|
683 | _executeHook('uponSanitizeElement', currentNode, {
|
684 | tagName: tagName,
|
685 | allowedTags: ALLOWED_TAGS
|
686 | });
|
687 |
|
688 |
|
689 | if ((tagName === 'svg' || tagName === 'math') && currentNode.querySelectorAll('p, br').length !== 0) {
|
690 | _forceRemove(currentNode);
|
691 | return true;
|
692 | }
|
693 |
|
694 |
|
695 | if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
|
696 |
|
697 | if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && typeof currentNode.insertAdjacentHTML === 'function') {
|
698 | try {
|
699 | var htmlToInsert = currentNode.innerHTML;
|
700 | currentNode.insertAdjacentHTML('AfterEnd', trustedTypesPolicy ? trustedTypesPolicy.createHTML(htmlToInsert) : htmlToInsert);
|
701 | } catch (_) {}
|
702 | }
|
703 |
|
704 | _forceRemove(currentNode);
|
705 | return true;
|
706 | }
|
707 |
|
708 |
|
709 | if (tagName === 'noscript' && regExpTest(/<\/noscript/i, currentNode.innerHTML)) {
|
710 | _forceRemove(currentNode);
|
711 | return true;
|
712 | }
|
713 |
|
714 | if (tagName === 'noembed' && regExpTest(/<\/noembed/i, currentNode.innerHTML)) {
|
715 | _forceRemove(currentNode);
|
716 | return true;
|
717 | }
|
718 |
|
719 |
|
720 | if (SAFE_FOR_JQUERY && !currentNode.firstElementChild && (!currentNode.content || !currentNode.content.firstElementChild) && regExpTest(/</g, currentNode.textContent)) {
|
721 | arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
|
722 | if (currentNode.innerHTML) {
|
723 | currentNode.innerHTML = stringReplace(currentNode.innerHTML, /</g, '<');
|
724 | } else {
|
725 | currentNode.innerHTML = stringReplace(currentNode.textContent, /</g, '<');
|
726 | }
|
727 | }
|
728 |
|
729 | /* Sanitize element content to be template-safe */
|
730 | if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
|
731 | /* Get the element's text content */
|
732 | content = currentNode.textContent;
|
733 | content = stringReplace(content, MUSTACHE_EXPR$$1, ' ');
|
734 | content = stringReplace(content, ERB_EXPR$$1, ' ');
|
735 | if (currentNode.textContent !== content) {
|
736 | arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
|
737 | currentNode.textContent = content;
|
738 | }
|
739 | }
|
740 |
|
741 | /* Execute a hook if present */
|
742 | _executeHook('afterSanitizeElements', currentNode, null);
|
743 |
|
744 | return false;
|
745 | };
|
746 |
|
747 | /**
|
748 | * _isValidAttribute
|
749 | *
|
750 | * @param {string} lcTag Lowercase tag name of containing element.
|
751 | * @param {string} lcName Lowercase attribute name.
|
752 | * @param {string} value Attribute value.
|
753 | * @return {Boolean} Returns true if `value` is valid, otherwise false.
|
754 | */
|
755 | // eslint-disable-next-line complexity
|
756 | var _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
|
757 | /* Make sure attribute cannot clobber */
|
758 | if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
|
759 | return false;
|
760 | }
|
761 |
|
762 | /* Allow valid data-* attributes: At least one character after "-"
|
763 | (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
|
764 | XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
|
765 | We don't need to check the value; it's always URI safe. */
|
766 | if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$$1, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$$1, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
|
767 | return false;
|
768 |
|
769 | /* Check value is safe. First, is attr inert? If so, is safe */
|
770 | } 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 {
|
771 | return false;
|
772 | }
|
773 |
|
774 | return true;
|
775 | };
|
776 |
|
777 | /**
|
778 | * _sanitizeAttributes
|
779 | *
|
780 | * @protect attributes
|
781 | * @protect nodeName
|
782 | * @protect removeAttribute
|
783 | * @protect setAttribute
|
784 | *
|
785 | * @param {Node} currentNode to sanitize
|
786 | */
|
787 | // eslint-disable-next-line complexity
|
788 | var _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
|
789 | var attr = void 0;
|
790 | var value = void 0;
|
791 | var lcName = void 0;
|
792 | var idAttr = void 0;
|
793 | var l = void 0;
|
794 | /* Execute a hook if present */
|
795 | _executeHook('beforeSanitizeAttributes', currentNode, null);
|
796 |
|
797 | var attributes = currentNode.attributes;
|
798 |
|
799 | /* Check if we have attributes; if not we might have a text node */
|
800 |
|
801 | if (!attributes) {
|
802 | return;
|
803 | }
|
804 |
|
805 | var hookEvent = {
|
806 | attrName: '',
|
807 | attrValue: '',
|
808 | keepAttr: true,
|
809 | allowedAttributes: ALLOWED_ATTR
|
810 | };
|
811 | l = attributes.length;
|
812 |
|
813 | /* Go backwards over all attributes; safely remove bad ones */
|
814 | while (l--) {
|
815 | attr = attributes[l];
|
816 | var _attr = attr,
|
817 | name = _attr.name,
|
818 | namespaceURI = _attr.namespaceURI;
|
819 |
|
820 | value = stringTrim(attr.value);
|
821 | lcName = stringToLowerCase(name);
|
822 |
|
823 | /* Execute a hook if present */
|
824 | hookEvent.attrName = lcName;
|
825 | hookEvent.attrValue = value;
|
826 | hookEvent.keepAttr = true;
|
827 | hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
|
828 | _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
|
829 | value = hookEvent.attrValue;
|
830 | /* Did the hooks approve of the attribute? */
|
831 | if (hookEvent.forceKeepAttr) {
|
832 | continue;
|
833 | }
|
834 |
|
835 | /* Remove attribute */
|
836 | // Safari (iOS + Mac), last tested v8.0.5, crashes if you try to
|
837 | // remove a "name" attribute from an <img> tag that has an "id"
|
838 | // attribute at the time.
|
839 | if (lcName === 'name' && currentNode.nodeName === 'IMG' && attributes.id) {
|
840 | idAttr = attributes.id;
|
841 | attributes = arraySlice(attributes, []);
|
842 | _removeAttribute('id', currentNode);
|
843 | _removeAttribute(name, currentNode);
|
844 | if (arrayIndexOf(attributes, idAttr) > l) {
|
845 | currentNode.setAttribute('id', idAttr.value);
|
846 | }
|
847 | } else if (
|
848 | // This works around a bug in Safari, where input[type=file]
|
849 | // cannot be dynamically set after type has been removed
|
850 | currentNode.nodeName === 'INPUT' && lcName === 'type' && value === 'file' && hookEvent.keepAttr && (ALLOWED_ATTR[lcName] || !FORBID_ATTR[lcName])) {
|
851 | continue;
|
852 | } else {
|
853 | // This avoids a crash in Safari v9.0 with double-ids.
|
854 | // The trick is to first set the id to be empty and then to
|
855 | // remove the attribute
|
856 | if (name === 'id') {
|
857 | currentNode.setAttribute(name, '');
|
858 | }
|
859 |
|
860 | _removeAttribute(name, currentNode);
|
861 | }
|
862 |
|
863 | /* Did the hooks approve of the attribute? */
|
864 | if (!hookEvent.keepAttr) {
|
865 | continue;
|
866 | }
|
867 |
|
868 | /* Work around a security issue in jQuery 3.0 */
|
869 | if (SAFE_FOR_JQUERY && regExpTest(/\/>/i, value)) {
|
870 | _removeAttribute(name, currentNode);
|
871 | continue;
|
872 | }
|
873 |
|
874 | /* Take care of an mXSS pattern using namespace switches */
|
875 | if (regExpTest(/svg|math/i, currentNode.namespaceURI) && regExpTest(regExpCreate('</(' + arrayJoin(objectKeys(FORBID_CONTENTS), '|') + ')', 'i'), value)) {
|
876 | _removeAttribute(name, currentNode);
|
877 | continue;
|
878 | }
|
879 |
|
880 | /* Sanitize attribute content to be template-safe */
|
881 | if (SAFE_FOR_TEMPLATES) {
|
882 | value = stringReplace(value, MUSTACHE_EXPR$$1, ' ');
|
883 | value = stringReplace(value, ERB_EXPR$$1, ' ');
|
884 | }
|
885 |
|
886 | /* Is `value` valid for this attribute? */
|
887 | var lcTag = currentNode.nodeName.toLowerCase();
|
888 | if (!_isValidAttribute(lcTag, lcName, value)) {
|
889 | continue;
|
890 | }
|
891 |
|
892 | /* Handle invalid data-* attribute set by try-catching it */
|
893 | try {
|
894 | if (namespaceURI) {
|
895 | currentNode.setAttributeNS(namespaceURI, name, value);
|
896 | } else {
|
897 | /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
|
898 | currentNode.setAttribute(name, value);
|
899 | }
|
900 |
|
901 | arrayPop(DOMPurify.removed);
|
902 | } catch (_) {}
|
903 | }
|
904 |
|
905 | /* Execute a hook if present */
|
906 | _executeHook('afterSanitizeAttributes', currentNode, null);
|
907 | };
|
908 |
|
909 | /**
|
910 | * _sanitizeShadowDOM
|
911 | *
|
912 | * @param {DocumentFragment} fragment to iterate over recursively
|
913 | */
|
914 | var _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
|
915 | var shadowNode = void 0;
|
916 | var shadowIterator = _createIterator(fragment);
|
917 |
|
918 | /* Execute a hook if present */
|
919 | _executeHook('beforeSanitizeShadowDOM', fragment, null);
|
920 |
|
921 | while (shadowNode = shadowIterator.nextNode()) {
|
922 | /* Execute a hook if present */
|
923 | _executeHook('uponSanitizeShadowNode', shadowNode, null);
|
924 |
|
925 | /* Sanitize tags and elements */
|
926 | if (_sanitizeElements(shadowNode)) {
|
927 | continue;
|
928 | }
|
929 |
|
930 | /* Deep shadow DOM detected */
|
931 | if (shadowNode.content instanceof DocumentFragment) {
|
932 | _sanitizeShadowDOM(shadowNode.content);
|
933 | }
|
934 |
|
935 | /* Check attributes, sanitize if necessary */
|
936 | _sanitizeAttributes(shadowNode);
|
937 | }
|
938 |
|
939 | /* Execute a hook if present */
|
940 | _executeHook('afterSanitizeShadowDOM', fragment, null);
|
941 | };
|
942 |
|
943 | /**
|
944 | * Sanitize
|
945 | * Public method providing core sanitation functionality
|
946 | *
|
947 | * @param {String|Node} dirty string or DOM node
|
948 | * @param {Object} configuration object
|
949 | */
|
950 | // eslint-disable-next-line complexity
|
951 | DOMPurify.sanitize = function (dirty, cfg) {
|
952 | var body = void 0;
|
953 | var importedNode = void 0;
|
954 | var currentNode = void 0;
|
955 | var oldNode = void 0;
|
956 | var returnNode = void 0;
|
957 | /* Make sure we have a string to sanitize.
|
958 | DO NOT return early, as this will return the wrong type if
|
959 | the user has requested a DOM object rather than a string */
|
960 | if (!dirty) {
|
961 | dirty = ' |
962 | }
|
963 |
|
964 | /* Stringify, in case dirty is an object */
|
965 | if (typeof dirty !== 'string' && !_isNode(dirty)) {
|
966 | // eslint-disable-next-line no-negated-condition
|
967 | if (typeof dirty.toString !== 'function') {
|
968 | throw typeErrorCreate('toString is not a function');
|
969 | } else {
|
970 | dirty = dirty.toString();
|
971 | if (typeof dirty !== 'string') {
|
972 | throw typeErrorCreate('dirty is not a string, aborting');
|
973 | }
|
974 | }
|
975 | }
|
976 |
|
977 | /* Check we can run. Otherwise fall back or ignore */
|
978 | if (!DOMPurify.isSupported) {
|
979 | if (_typeof(window.toStaticHTML) === 'object' || typeof window.toStaticHTML === 'function') {
|
980 | if (typeof dirty === 'string') {
|
981 | return window.toStaticHTML(dirty);
|
982 | }
|
983 |
|
984 | if (_isNode(dirty)) {
|
985 | return window.toStaticHTML(dirty.outerHTML);
|
986 | }
|
987 | }
|
988 |
|
989 | return dirty;
|
990 | }
|
991 |
|
992 | /* Assign config vars */
|
993 | if (!SET_CONFIG) {
|
994 | _parseConfig(cfg);
|
995 | }
|
996 |
|
997 | /* Clean up removed elements */
|
998 | DOMPurify.removed = [];
|
999 |
|
1000 | /* Check if dirty is correctly typed for IN_PLACE */
|
1001 | if (typeof dirty === 'string') {
|
1002 | IN_PLACE = false;
|
1003 | }
|
1004 |
|
1005 | if (IN_PLACE) ; else if (dirty instanceof Node) {
|
1006 | /* If dirty is a DOM element, append to an empty document to avoid
|
1007 | elements being stripped by the parser */
|
1008 | body = _initDocument(' |
1009 | importedNode = body.ownerDocument.importNode(dirty, true);
|
1010 | if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
|
1011 | /* Node is already a body, use as is */
|
1012 | body = importedNode;
|
1013 | } else if (importedNode.nodeName === 'HTML') {
|
1014 | body = importedNode;
|
1015 | } else {
|
1016 | // eslint-disable-next-line unicorn/prefer-node-append
|
1017 | body.appendChild(importedNode);
|
1018 | }
|
1019 | } else {
|
1020 | /* Exit directly if we have nothing to do */
|
1021 | if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
|
1022 | // eslint-disable-next-line unicorn/prefer-includes
|
1023 | dirty.indexOf('<') === -1) {
|
1024 | return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
|
1025 | }
|
1026 |
|
1027 | /* Initialize the document to work on */
|
1028 | body = _initDocument(dirty);
|
1029 |
|
1030 | /* Check we have a DOM node from the data */
|
1031 | if (!body) {
|
1032 | return RETURN_DOM ? null : emptyHTML;
|
1033 | }
|
1034 | }
|
1035 |
|
1036 | /* Remove first element node (ours) if FORCE_BODY is set */
|
1037 | if (body && FORCE_BODY) {
|
1038 | _forceRemove(body.firstChild);
|
1039 | }
|
1040 |
|
1041 | /* Get node iterator */
|
1042 | var nodeIterator = _createIterator(IN_PLACE ? dirty : body);
|
1043 |
|
1044 | /* Now start iterating over the created document */
|
1045 | while (currentNode = nodeIterator.nextNode()) {
|
1046 | /* Fix IE's strange behavior with manipulated textNodes #89 */
|
1047 | if (currentNode.nodeType === 3 && currentNode === oldNode) {
|
1048 | continue;
|
1049 | }
|
1050 |
|
1051 | /* Sanitize tags and elements */
|
1052 | if (_sanitizeElements(currentNode)) {
|
1053 | continue;
|
1054 | }
|
1055 |
|
1056 | /* Shadow DOM detected, sanitize it */
|
1057 | if (currentNode.content instanceof DocumentFragment) {
|
1058 | _sanitizeShadowDOM(currentNode.content);
|
1059 | }
|
1060 |
|
1061 | /* Check attributes, sanitize if necessary */
|
1062 | _sanitizeAttributes(currentNode);
|
1063 |
|
1064 | oldNode = currentNode;
|
1065 | }
|
1066 |
|
1067 | oldNode = null;
|
1068 |
|
1069 | /* If we sanitized `dirty` in-place, return it. */
|
1070 | if (IN_PLACE) {
|
1071 | return dirty;
|
1072 | }
|
1073 |
|
1074 | /* Return sanitized string or DOM */
|
1075 | if (RETURN_DOM) {
|
1076 | if (RETURN_DOM_FRAGMENT) {
|
1077 | returnNode = createDocumentFragment.call(body.ownerDocument);
|
1078 |
|
1079 | while (body.firstChild) {
|
1080 | // eslint-disable-next-line unicorn/prefer-node-append
|
1081 | returnNode.appendChild(body.firstChild);
|
1082 | }
|
1083 | } else {
|
1084 | returnNode = body;
|
1085 | }
|
1086 |
|
1087 | if (RETURN_DOM_IMPORT) {
|
1088 | /*
|
1089 | AdoptNode() is not used because internal state is not reset
|
1090 | (e.g. the past names map of a HTMLFormElement), this is safe
|
1091 | in theory but we would rather not risk another attack vector.
|
1092 | The state that is cloned by importNode() is explicitly defined
|
1093 | by the specs.
|
1094 | */
|
1095 | returnNode = importNode.call(originalDocument, returnNode, true);
|
1096 | }
|
1097 |
|
1098 | return returnNode;
|
1099 | }
|
1100 |
|
1101 | var serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
|
1102 |
|
1103 | /* Sanitize final string template-safe */
|
1104 | if (SAFE_FOR_TEMPLATES) {
|
1105 | serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR$$1, ' ');
|
1106 | serializedHTML = stringReplace(serializedHTML, ERB_EXPR$$1, ' ');
|
1107 | }
|
1108 |
|
1109 | return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
|
1110 | };
|
1111 |
|
1112 | /**
|
1113 | * Public method to set the configuration once
|
1114 | * setConfig
|
1115 | *
|
1116 | * @param {Object} cfg configuration object
|
1117 | */
|
1118 | DOMPurify.setConfig = function (cfg) {
|
1119 | _parseConfig(cfg);
|
1120 | SET_CONFIG = true;
|
1121 | };
|
1122 |
|
1123 | /**
|
1124 | * Public method to remove the configuration
|
1125 | * clearConfig
|
1126 | *
|
1127 | */
|
1128 | DOMPurify.clearConfig = function () {
|
1129 | CONFIG = null;
|
1130 | SET_CONFIG = false;
|
1131 | };
|
1132 |
|
1133 | /**
|
1134 | * Public method to check if an attribute value is valid.
|
1135 | * Uses last set config, if any. Otherwise, uses config defaults.
|
1136 | * isValidAttribute
|
1137 | *
|
1138 | * @param {string} tag Tag name of containing element.
|
1139 | * @param {string} attr Attribute name.
|
1140 | * @param {string} value Attribute value.
|
1141 | * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
|
1142 | */
|
1143 | DOMPurify.isValidAttribute = function (tag, attr, value) {
|
1144 | /* Initialize shared config vars if necessary. */
|
1145 | if (!CONFIG) {
|
1146 | _parseConfig({});
|
1147 | }
|
1148 |
|
1149 | var lcTag = stringToLowerCase(tag);
|
1150 | var lcName = stringToLowerCase(attr);
|
1151 | return _isValidAttribute(lcTag, lcName, value);
|
1152 | };
|
1153 |
|
1154 | /**
|
1155 | * AddHook
|
1156 | * Public method to add DOMPurify hooks
|
1157 | *
|
1158 | * @param {String} entryPoint entry point for the hook to add
|
1159 | * @param {Function} hookFunction function to execute
|
1160 | */
|
1161 | DOMPurify.addHook = function (entryPoint, hookFunction) {
|
1162 | if (typeof hookFunction !== 'function') {
|
1163 | return;
|
1164 | }
|
1165 |
|
1166 | hooks[entryPoint] = hooks[entryPoint] || [];
|
1167 | arrayPush(hooks[entryPoint], hookFunction);
|
1168 | };
|
1169 |
|
1170 | /**
|
1171 | * RemoveHook
|
1172 | * Public method to remove a DOMPurify hook at a given entryPoint
|
1173 | * (pops it from the stack of hooks if more are present)
|
1174 | *
|
1175 | * @param {String} entryPoint entry point for the hook to remove
|
1176 | */
|
1177 | DOMPurify.removeHook = function (entryPoint) {
|
1178 | if (hooks[entryPoint]) {
|
1179 | arrayPop(hooks[entryPoint]);
|
1180 | }
|
1181 | };
|
1182 |
|
1183 | /**
|
1184 | * RemoveHooks
|
1185 | * Public method to remove all DOMPurify hooks at a given entryPoint
|
1186 | *
|
1187 | * @param {String} entryPoint entry point for the hooks to remove
|
1188 | */
|
1189 | DOMPurify.removeHooks = function (entryPoint) {
|
1190 | if (hooks[entryPoint]) {
|
1191 | hooks[entryPoint] = [];
|
1192 | }
|
1193 | };
|
1194 |
|
1195 | /**
|
1196 | * RemoveAllHooks
|
1197 | * Public method to remove all DOMPurify hooks
|
1198 | *
|
1199 | */
|
1200 | DOMPurify.removeAllHooks = function () {
|
1201 | hooks = {};
|
1202 | };
|
1203 |
|
1204 | return DOMPurify;
|
1205 | }
|
1206 |
|
1207 | var purify = createDOMPurify();
|
1208 |
|
1209 | export default purify;
|
1210 | //# sourceMappingURL=purify.es.js.map
|
1211 |
|
\ | No newline at end of file |