@bigbinary/neeto-commons-frontend 2.0.75 → 2.0.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/initializers.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { useErrorDisplayStore } from '@bigbinary/neeto-commons-frontend/react-utils';
2
2
  export { useDisplayErrorPage } from '@bigbinary/neeto-commons-frontend/react-utils';
3
3
  import axios from 'axios';
4
- import i18next from 'i18next';
4
+ import i18n from 'i18next';
5
5
  import { serializeKeysToSnakeCase, keysToCamelCase, matches, deepFreezeObject } from '@bigbinary/neeto-commons-frontend/pure';
6
6
  import { resetAuthTokens } from '@bigbinary/neeto-commons-frontend/utils';
7
7
  import { Toastr } from '@bigbinary/neetoui';
8
- import { evolve, omit, values, mergeDeepLeft, either, isEmpty, isNil } from 'ramda';
8
+ import { evolve, omit, values, mergeDeepLeft, curry, mergeAll, either, isEmpty, isNil } from 'ramda';
9
9
  import { initReactI18next } from 'react-i18next';
10
10
  import Logger from 'js-logger';
11
11
  import mixpanel from 'mixpanel-browser';
@@ -164,7 +164,7 @@ var showErrorToastr = function showErrorToastr(error) {
164
164
  if (!showToastr) return error;
165
165
  if (error.message === "Network Error") {
166
166
  // @ts-ignore
167
- Toastr.error(i18next.t("neetoCommons.toastr.error.networkError"));
167
+ Toastr.error(i18n.t("neetoCommons.toastr.error.networkError"));
168
168
  } else if (![403, 404].includes((_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) && !axios.isCancel(error)) {
169
169
  // we already display a page in case of 403 & 404 and we don't want to show a toastr for cancelled requests.
170
170
  Toastr.error(error);
@@ -240,6 +240,1629 @@ function initializeGlobalProps() {
240
240
  deepFreezeObject(window.globalProps);
241
241
  }
242
242
 
243
+ /*! @license DOMPurify 3.0.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.3/LICENSE */
244
+
245
+ const {
246
+ entries,
247
+ setPrototypeOf,
248
+ isFrozen,
249
+ getPrototypeOf,
250
+ getOwnPropertyDescriptor
251
+ } = Object;
252
+ let {
253
+ freeze,
254
+ seal,
255
+ create
256
+ } = Object; // eslint-disable-line import/no-mutable-exports
257
+
258
+ let {
259
+ apply,
260
+ construct
261
+ } = typeof Reflect !== 'undefined' && Reflect;
262
+
263
+ if (!apply) {
264
+ apply = function apply(fun, thisValue, args) {
265
+ return fun.apply(thisValue, args);
266
+ };
267
+ }
268
+
269
+ if (!freeze) {
270
+ freeze = function freeze(x) {
271
+ return x;
272
+ };
273
+ }
274
+
275
+ if (!seal) {
276
+ seal = function seal(x) {
277
+ return x;
278
+ };
279
+ }
280
+
281
+ if (!construct) {
282
+ construct = function construct(Func, args) {
283
+ return new Func(...args);
284
+ };
285
+ }
286
+
287
+ const arrayForEach = unapply(Array.prototype.forEach);
288
+ const arrayPop = unapply(Array.prototype.pop);
289
+ const arrayPush = unapply(Array.prototype.push);
290
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
291
+ const stringToString = unapply(String.prototype.toString);
292
+ const stringMatch = unapply(String.prototype.match);
293
+ const stringReplace = unapply(String.prototype.replace);
294
+ const stringIndexOf = unapply(String.prototype.indexOf);
295
+ const stringTrim = unapply(String.prototype.trim);
296
+ const regExpTest = unapply(RegExp.prototype.test);
297
+ const typeErrorCreate = unconstruct(TypeError);
298
+ function unapply(func) {
299
+ return function (thisArg) {
300
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
301
+ args[_key - 1] = arguments[_key];
302
+ }
303
+
304
+ return apply(func, thisArg, args);
305
+ };
306
+ }
307
+ function unconstruct(func) {
308
+ return function () {
309
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
310
+ args[_key2] = arguments[_key2];
311
+ }
312
+
313
+ return construct(func, args);
314
+ };
315
+ }
316
+ /* Add properties to a lookup table */
317
+
318
+ function addToSet(set, array, transformCaseFunc) {
319
+ var _transformCaseFunc;
320
+
321
+ transformCaseFunc = (_transformCaseFunc = transformCaseFunc) !== null && _transformCaseFunc !== void 0 ? _transformCaseFunc : stringToLowerCase;
322
+
323
+ if (setPrototypeOf) {
324
+ // Make 'in' and truthy checks like Boolean(set.constructor)
325
+ // independent of any properties defined on Object.prototype.
326
+ // Prevent prototype setters from intercepting set as a this value.
327
+ setPrototypeOf(set, null);
328
+ }
329
+
330
+ let l = array.length;
331
+
332
+ while (l--) {
333
+ let element = array[l];
334
+
335
+ if (typeof element === 'string') {
336
+ const lcElement = transformCaseFunc(element);
337
+
338
+ if (lcElement !== element) {
339
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
340
+ if (!isFrozen(array)) {
341
+ array[l] = lcElement;
342
+ }
343
+
344
+ element = lcElement;
345
+ }
346
+ }
347
+
348
+ set[element] = true;
349
+ }
350
+
351
+ return set;
352
+ }
353
+ /* Shallow clone an object */
354
+
355
+ function clone(object) {
356
+ const newObject = create(null);
357
+
358
+ for (const [property, value] of entries(object)) {
359
+ newObject[property] = value;
360
+ }
361
+
362
+ return newObject;
363
+ }
364
+ /* This method automatically checks if the prop is function
365
+ * or getter and behaves accordingly. */
366
+
367
+ function lookupGetter(object, prop) {
368
+ while (object !== null) {
369
+ const desc = getOwnPropertyDescriptor(object, prop);
370
+
371
+ if (desc) {
372
+ if (desc.get) {
373
+ return unapply(desc.get);
374
+ }
375
+
376
+ if (typeof desc.value === 'function') {
377
+ return unapply(desc.value);
378
+ }
379
+ }
380
+
381
+ object = getPrototypeOf(object);
382
+ }
383
+
384
+ function fallbackValue(element) {
385
+ console.warn('fallback value for', element);
386
+ return null;
387
+ }
388
+
389
+ return fallbackValue;
390
+ }
391
+
392
+ const 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
393
+
394
+ const 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']);
395
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', '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.
396
+ // We still need to know them so that we can do namespace
397
+ // checks properly in case one wants to add them to
398
+ // allow-list.
399
+
400
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', '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']);
401
+ const 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', 'mprescripts']); // Similarly to SVG, we want to know all MathML elements,
402
+ // even those that we disallow by default.
403
+
404
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
405
+ const text = freeze(['#text']);
406
+
407
+ const 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']);
408
+ const 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']);
409
+ const 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']);
410
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
411
+
412
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
413
+
414
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
415
+ const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
416
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
417
+
418
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
419
+
420
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
421
+ );
422
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
423
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
424
+ );
425
+ const DOCTYPE_NAME = seal(/^html$/i);
426
+
427
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
428
+ __proto__: null,
429
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
430
+ ERB_EXPR: ERB_EXPR,
431
+ TMPLIT_EXPR: TMPLIT_EXPR,
432
+ DATA_ATTR: DATA_ATTR,
433
+ ARIA_ATTR: ARIA_ATTR,
434
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
435
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
436
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
437
+ DOCTYPE_NAME: DOCTYPE_NAME
438
+ });
439
+
440
+ const getGlobal = () => typeof window === 'undefined' ? null : window;
441
+ /**
442
+ * Creates a no-op policy for internal use only.
443
+ * Don't export this function outside this module!
444
+ * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
445
+ * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
446
+ * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
447
+ * are not supported or creating the policy failed).
448
+ */
449
+
450
+
451
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
452
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
453
+ return null;
454
+ } // Allow the callers to control the unique policy name
455
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
456
+ // Policy creation with duplicate names throws in Trusted Types.
457
+
458
+
459
+ let suffix = null;
460
+ const ATTR_NAME = 'data-tt-policy-suffix';
461
+
462
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
463
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
464
+ }
465
+
466
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
467
+
468
+ try {
469
+ return trustedTypes.createPolicy(policyName, {
470
+ createHTML(html) {
471
+ return html;
472
+ },
473
+
474
+ createScriptURL(scriptUrl) {
475
+ return scriptUrl;
476
+ }
477
+
478
+ });
479
+ } catch (_) {
480
+ // Policy creation failed (most likely another DOMPurify script has
481
+ // already run). Skip creating the policy, as this will only cause errors
482
+ // if TT are enforced.
483
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
484
+ return null;
485
+ }
486
+ };
487
+
488
+ function createDOMPurify() {
489
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
490
+
491
+ const DOMPurify = root => createDOMPurify(root);
492
+ /**
493
+ * Version label, exposed for easier checks
494
+ * if DOMPurify is up to date or not
495
+ */
496
+
497
+
498
+ DOMPurify.version = '3.0.3';
499
+ /**
500
+ * Array of elements that DOMPurify removed during sanitation.
501
+ * Empty if nothing was removed.
502
+ */
503
+
504
+ DOMPurify.removed = [];
505
+
506
+ if (!window || !window.document || window.document.nodeType !== 9) {
507
+ // Not running in a browser, provide a factory function
508
+ // so that you can pass your own Window
509
+ DOMPurify.isSupported = false;
510
+ return DOMPurify;
511
+ }
512
+
513
+ const originalDocument = window.document;
514
+ const currentScript = originalDocument.currentScript;
515
+ let {
516
+ document
517
+ } = window;
518
+ const {
519
+ DocumentFragment,
520
+ HTMLTemplateElement,
521
+ Node,
522
+ Element,
523
+ NodeFilter,
524
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
525
+ HTMLFormElement,
526
+ DOMParser,
527
+ trustedTypes
528
+ } = window;
529
+ const ElementPrototype = Element.prototype;
530
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
531
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
532
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
533
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
534
+ // new document created via createHTMLDocument. As per the spec
535
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
536
+ // a new empty registry is used when creating a template contents owner
537
+ // document, so we use that as our parent document to ensure nothing
538
+ // is inherited.
539
+
540
+ if (typeof HTMLTemplateElement === 'function') {
541
+ const template = document.createElement('template');
542
+
543
+ if (template.content && template.content.ownerDocument) {
544
+ document = template.content.ownerDocument;
545
+ }
546
+ }
547
+
548
+ let trustedTypesPolicy;
549
+ let emptyHTML = '';
550
+ const {
551
+ implementation,
552
+ createNodeIterator,
553
+ createDocumentFragment,
554
+ getElementsByTagName
555
+ } = document;
556
+ const {
557
+ importNode
558
+ } = originalDocument;
559
+ let hooks = {};
560
+ /**
561
+ * Expose whether this browser supports running the full DOMPurify.
562
+ */
563
+
564
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
565
+ const {
566
+ MUSTACHE_EXPR,
567
+ ERB_EXPR,
568
+ TMPLIT_EXPR,
569
+ DATA_ATTR,
570
+ ARIA_ATTR,
571
+ IS_SCRIPT_OR_DATA,
572
+ ATTR_WHITESPACE
573
+ } = EXPRESSIONS;
574
+ let {
575
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
576
+ } = EXPRESSIONS;
577
+ /**
578
+ * We consider the elements and attributes below to be safe. Ideally
579
+ * don't add any new ones but feel free to remove unwanted ones.
580
+ */
581
+
582
+ /* allowed element names */
583
+
584
+ let ALLOWED_TAGS = null;
585
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
586
+ /* Allowed attribute names */
587
+
588
+ let ALLOWED_ATTR = null;
589
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
590
+ /*
591
+ * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
592
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
593
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
594
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
595
+ */
596
+
597
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
598
+ tagNameCheck: {
599
+ writable: true,
600
+ configurable: false,
601
+ enumerable: true,
602
+ value: null
603
+ },
604
+ attributeNameCheck: {
605
+ writable: true,
606
+ configurable: false,
607
+ enumerable: true,
608
+ value: null
609
+ },
610
+ allowCustomizedBuiltInElements: {
611
+ writable: true,
612
+ configurable: false,
613
+ enumerable: true,
614
+ value: false
615
+ }
616
+ }));
617
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
618
+
619
+ let FORBID_TAGS = null;
620
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
621
+
622
+ let FORBID_ATTR = null;
623
+ /* Decide if ARIA attributes are okay */
624
+
625
+ let ALLOW_ARIA_ATTR = true;
626
+ /* Decide if custom data attributes are okay */
627
+
628
+ let ALLOW_DATA_ATTR = true;
629
+ /* Decide if unknown protocols are okay */
630
+
631
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
632
+ /* Decide if self-closing tags in attributes are allowed.
633
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
634
+
635
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
636
+ /* Output should be safe for common template engines.
637
+ * This means, DOMPurify removes data attributes, mustaches and ERB
638
+ */
639
+
640
+ let SAFE_FOR_TEMPLATES = false;
641
+ /* Decide if document with <html>... should be returned */
642
+
643
+ let WHOLE_DOCUMENT = false;
644
+ /* Track whether config is already set on this instance of DOMPurify. */
645
+
646
+ let SET_CONFIG = false;
647
+ /* Decide if all elements (e.g. style, script) must be children of
648
+ * document.body. By default, browsers might move them to document.head */
649
+
650
+ let FORCE_BODY = false;
651
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
652
+ * string (or a TrustedHTML object if Trusted Types are supported).
653
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
654
+ */
655
+
656
+ let RETURN_DOM = false;
657
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
658
+ * string (or a TrustedHTML object if Trusted Types are supported) */
659
+
660
+ let RETURN_DOM_FRAGMENT = false;
661
+ /* Try to return a Trusted Type object instead of a string, return a string in
662
+ * case Trusted Types are not supported */
663
+
664
+ let RETURN_TRUSTED_TYPE = false;
665
+ /* Output should be free from DOM clobbering attacks?
666
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
667
+ */
668
+
669
+ let SANITIZE_DOM = true;
670
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
671
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
672
+ *
673
+ * HTML/DOM spec rules that enable DOM Clobbering:
674
+ * - Named Access on Window (§7.3.3)
675
+ * - DOM Tree Accessors (§3.1.5)
676
+ * - Form Element Parent-Child Relations (§4.10.3)
677
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
678
+ * - HTMLCollection (§4.2.10.2)
679
+ *
680
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
681
+ * with a constant string, i.e., `user-content-`
682
+ */
683
+
684
+ let SANITIZE_NAMED_PROPS = false;
685
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
686
+ /* Keep element content when removing element? */
687
+
688
+ let KEEP_CONTENT = true;
689
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
690
+ * of importing it into a new Document and returning a sanitized copy */
691
+
692
+ let IN_PLACE = false;
693
+ /* Allow usage of profiles like html, svg and mathMl */
694
+
695
+ let USE_PROFILES = {};
696
+ /* Tags to ignore content of when KEEP_CONTENT is true */
697
+
698
+ let FORBID_CONTENTS = null;
699
+ const 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']);
700
+ /* Tags that are safe for data: URIs */
701
+
702
+ let DATA_URI_TAGS = null;
703
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
704
+ /* Attributes safe for values like "javascript:" */
705
+
706
+ let URI_SAFE_ATTRIBUTES = null;
707
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
708
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
709
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
710
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
711
+ /* Document namespace */
712
+
713
+ let NAMESPACE = HTML_NAMESPACE;
714
+ let IS_EMPTY_INPUT = false;
715
+ /* Allowed XHTML+XML namespaces */
716
+
717
+ let ALLOWED_NAMESPACES = null;
718
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
719
+ /* Parsing of strict XHTML documents */
720
+
721
+ let PARSER_MEDIA_TYPE;
722
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
723
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
724
+ let transformCaseFunc;
725
+ /* Keep a reference to config to pass to hooks */
726
+
727
+ let CONFIG = null;
728
+ /* Ideally, do not touch anything below this line */
729
+
730
+ /* ______________________________________________ */
731
+
732
+ const formElement = document.createElement('form');
733
+
734
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
735
+ return testValue instanceof RegExp || testValue instanceof Function;
736
+ };
737
+ /**
738
+ * _parseConfig
739
+ *
740
+ * @param {Object} cfg optional config literal
741
+ */
742
+ // eslint-disable-next-line complexity
743
+
744
+
745
+ const _parseConfig = function _parseConfig(cfg) {
746
+ if (CONFIG && CONFIG === cfg) {
747
+ return;
748
+ }
749
+ /* Shield configuration object from tampering */
750
+
751
+
752
+ if (!cfg || typeof cfg !== 'object') {
753
+ cfg = {};
754
+ }
755
+ /* Shield configuration object from prototype pollution */
756
+
757
+
758
+ cfg = clone(cfg);
759
+ PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
760
+ 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.
761
+
762
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
763
+ /* Set configuration parameters */
764
+
765
+ ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
766
+ ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
767
+ ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
768
+ URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
769
+ cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
770
+ transformCaseFunc // eslint-disable-line indent
771
+ ) // eslint-disable-line indent
772
+ : DEFAULT_URI_SAFE_ATTRIBUTES;
773
+ DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
774
+ cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
775
+ transformCaseFunc // eslint-disable-line indent
776
+ ) // eslint-disable-line indent
777
+ : DEFAULT_DATA_URI_TAGS;
778
+ FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
779
+ FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
780
+ FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
781
+ USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
782
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
783
+
784
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
785
+
786
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
787
+
788
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
789
+
790
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
791
+
792
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
793
+
794
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
795
+
796
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
797
+
798
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
799
+
800
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
801
+
802
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
803
+
804
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
805
+
806
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
807
+
808
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
809
+
810
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
811
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
812
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
813
+
814
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
815
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
816
+ }
817
+
818
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
819
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
820
+ }
821
+
822
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
823
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
824
+ }
825
+
826
+ if (SAFE_FOR_TEMPLATES) {
827
+ ALLOW_DATA_ATTR = false;
828
+ }
829
+
830
+ if (RETURN_DOM_FRAGMENT) {
831
+ RETURN_DOM = true;
832
+ }
833
+ /* Parse profile info */
834
+
835
+
836
+ if (USE_PROFILES) {
837
+ ALLOWED_TAGS = addToSet({}, [...text]);
838
+ ALLOWED_ATTR = [];
839
+
840
+ if (USE_PROFILES.html === true) {
841
+ addToSet(ALLOWED_TAGS, html$1);
842
+ addToSet(ALLOWED_ATTR, html);
843
+ }
844
+
845
+ if (USE_PROFILES.svg === true) {
846
+ addToSet(ALLOWED_TAGS, svg$1);
847
+ addToSet(ALLOWED_ATTR, svg);
848
+ addToSet(ALLOWED_ATTR, xml);
849
+ }
850
+
851
+ if (USE_PROFILES.svgFilters === true) {
852
+ addToSet(ALLOWED_TAGS, svgFilters);
853
+ addToSet(ALLOWED_ATTR, svg);
854
+ addToSet(ALLOWED_ATTR, xml);
855
+ }
856
+
857
+ if (USE_PROFILES.mathMl === true) {
858
+ addToSet(ALLOWED_TAGS, mathMl$1);
859
+ addToSet(ALLOWED_ATTR, mathMl);
860
+ addToSet(ALLOWED_ATTR, xml);
861
+ }
862
+ }
863
+ /* Merge configuration parameters */
864
+
865
+
866
+ if (cfg.ADD_TAGS) {
867
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
868
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
869
+ }
870
+
871
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
872
+ }
873
+
874
+ if (cfg.ADD_ATTR) {
875
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
876
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
877
+ }
878
+
879
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
880
+ }
881
+
882
+ if (cfg.ADD_URI_SAFE_ATTR) {
883
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
884
+ }
885
+
886
+ if (cfg.FORBID_CONTENTS) {
887
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
888
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
889
+ }
890
+
891
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
892
+ }
893
+ /* Add #text in case KEEP_CONTENT is set to true */
894
+
895
+
896
+ if (KEEP_CONTENT) {
897
+ ALLOWED_TAGS['#text'] = true;
898
+ }
899
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
900
+
901
+
902
+ if (WHOLE_DOCUMENT) {
903
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
904
+ }
905
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
906
+
907
+
908
+ if (ALLOWED_TAGS.table) {
909
+ addToSet(ALLOWED_TAGS, ['tbody']);
910
+ delete FORBID_TAGS.tbody;
911
+ }
912
+
913
+ if (cfg.TRUSTED_TYPES_POLICY) {
914
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
915
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
916
+ }
917
+
918
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
919
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
920
+ } // Overwrite existing TrustedTypes policy.
921
+
922
+
923
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY; // Sign local variables required by `sanitize`.
924
+
925
+ emptyHTML = trustedTypesPolicy.createHTML('');
926
+ } else {
927
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
928
+ if (trustedTypesPolicy === undefined) {
929
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
930
+ } // If creating the internal policy succeeded sign internal variables.
931
+
932
+
933
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
934
+ emptyHTML = trustedTypesPolicy.createHTML('');
935
+ }
936
+ } // Prevent further manipulation of configuration.
937
+ // Not available in IE8, Safari 5, etc.
938
+
939
+
940
+ if (freeze) {
941
+ freeze(cfg);
942
+ }
943
+
944
+ CONFIG = cfg;
945
+ };
946
+
947
+ const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
948
+ const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
949
+ // namespace. We need to specify them explicitly
950
+ // so that they don't get erroneously deleted from
951
+ // HTML namespace.
952
+
953
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
954
+ /* Keep track of all possible SVG and MathML tags
955
+ * so that we can perform the namespace checks
956
+ * correctly. */
957
+
958
+ const ALL_SVG_TAGS = addToSet({}, svg$1);
959
+ addToSet(ALL_SVG_TAGS, svgFilters);
960
+ addToSet(ALL_SVG_TAGS, svgDisallowed);
961
+ const ALL_MATHML_TAGS = addToSet({}, mathMl$1);
962
+ addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
963
+ /**
964
+ *
965
+ *
966
+ * @param {Element} element a DOM element whose namespace is being checked
967
+ * @returns {boolean} Return false if the element has a
968
+ * namespace that a spec-compliant parser would never
969
+ * return. Return true otherwise.
970
+ */
971
+
972
+ const _checkValidNamespace = function _checkValidNamespace(element) {
973
+ let parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
974
+ // can be null. We just simulate parent in this case.
975
+
976
+ if (!parent || !parent.tagName) {
977
+ parent = {
978
+ namespaceURI: NAMESPACE,
979
+ tagName: 'template'
980
+ };
981
+ }
982
+
983
+ const tagName = stringToLowerCase(element.tagName);
984
+ const parentTagName = stringToLowerCase(parent.tagName);
985
+
986
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
987
+ return false;
988
+ }
989
+
990
+ if (element.namespaceURI === SVG_NAMESPACE) {
991
+ // The only way to switch from HTML namespace to SVG
992
+ // is via <svg>. If it happens via any other tag, then
993
+ // it should be killed.
994
+ if (parent.namespaceURI === HTML_NAMESPACE) {
995
+ return tagName === 'svg';
996
+ } // The only way to switch from MathML to SVG is via`
997
+ // svg if parent is either <annotation-xml> or MathML
998
+ // text integration points.
999
+
1000
+
1001
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
1002
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1003
+ } // We only allow elements that are defined in SVG
1004
+ // spec. All others are disallowed in SVG namespace.
1005
+
1006
+
1007
+ return Boolean(ALL_SVG_TAGS[tagName]);
1008
+ }
1009
+
1010
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1011
+ // The only way to switch from HTML namespace to MathML
1012
+ // is via <math>. If it happens via any other tag, then
1013
+ // it should be killed.
1014
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1015
+ return tagName === 'math';
1016
+ } // The only way to switch from SVG to MathML is via
1017
+ // <math> and HTML integration points
1018
+
1019
+
1020
+ if (parent.namespaceURI === SVG_NAMESPACE) {
1021
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1022
+ } // We only allow elements that are defined in MathML
1023
+ // spec. All others are disallowed in MathML namespace.
1024
+
1025
+
1026
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1027
+ }
1028
+
1029
+ if (element.namespaceURI === HTML_NAMESPACE) {
1030
+ // The only way to switch from SVG to HTML is via
1031
+ // HTML integration points, and from MathML to HTML
1032
+ // is via MathML text integration points
1033
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1034
+ return false;
1035
+ }
1036
+
1037
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1038
+ return false;
1039
+ } // We disallow tags that are specific for MathML
1040
+ // or SVG and should never appear in HTML namespace
1041
+
1042
+
1043
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1044
+ } // For XHTML and XML documents that support custom namespaces
1045
+
1046
+
1047
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1048
+ return true;
1049
+ } // The code should never reach this place (this means
1050
+ // that the element somehow got namespace that is not
1051
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1052
+ // Return false just in case.
1053
+
1054
+
1055
+ return false;
1056
+ };
1057
+ /**
1058
+ * _forceRemove
1059
+ *
1060
+ * @param {Node} node a DOM node
1061
+ */
1062
+
1063
+
1064
+ const _forceRemove = function _forceRemove(node) {
1065
+ arrayPush(DOMPurify.removed, {
1066
+ element: node
1067
+ });
1068
+
1069
+ try {
1070
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
1071
+ node.parentNode.removeChild(node);
1072
+ } catch (_) {
1073
+ node.remove();
1074
+ }
1075
+ };
1076
+ /**
1077
+ * _removeAttribute
1078
+ *
1079
+ * @param {String} name an Attribute name
1080
+ * @param {Node} node a DOM node
1081
+ */
1082
+
1083
+
1084
+ const _removeAttribute = function _removeAttribute(name, node) {
1085
+ try {
1086
+ arrayPush(DOMPurify.removed, {
1087
+ attribute: node.getAttributeNode(name),
1088
+ from: node
1089
+ });
1090
+ } catch (_) {
1091
+ arrayPush(DOMPurify.removed, {
1092
+ attribute: null,
1093
+ from: node
1094
+ });
1095
+ }
1096
+
1097
+ node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
1098
+
1099
+ if (name === 'is' && !ALLOWED_ATTR[name]) {
1100
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1101
+ try {
1102
+ _forceRemove(node);
1103
+ } catch (_) {}
1104
+ } else {
1105
+ try {
1106
+ node.setAttribute(name, '');
1107
+ } catch (_) {}
1108
+ }
1109
+ }
1110
+ };
1111
+ /**
1112
+ * _initDocument
1113
+ *
1114
+ * @param {String} dirty a string of dirty markup
1115
+ * @return {Document} a DOM, filled with the dirty markup
1116
+ */
1117
+
1118
+
1119
+ const _initDocument = function _initDocument(dirty) {
1120
+ /* Create a HTML document */
1121
+ let doc;
1122
+ let leadingWhitespace;
1123
+
1124
+ if (FORCE_BODY) {
1125
+ dirty = '<remove></remove>' + dirty;
1126
+ } else {
1127
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
1128
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1129
+ leadingWhitespace = matches && matches[0];
1130
+ }
1131
+
1132
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1133
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1134
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1135
+ }
1136
+
1137
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1138
+ /*
1139
+ * Use the DOMParser API by default, fallback later if needs be
1140
+ * DOMParser not work for svg when has multiple root element.
1141
+ */
1142
+
1143
+ if (NAMESPACE === HTML_NAMESPACE) {
1144
+ try {
1145
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1146
+ } catch (_) {}
1147
+ }
1148
+ /* Use createHTMLDocument in case DOMParser is not available */
1149
+
1150
+
1151
+ if (!doc || !doc.documentElement) {
1152
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
1153
+
1154
+ try {
1155
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1156
+ } catch (_) {// Syntax error if dirtyPayload is invalid xml
1157
+ }
1158
+ }
1159
+
1160
+ const body = doc.body || doc.documentElement;
1161
+
1162
+ if (dirty && leadingWhitespace) {
1163
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1164
+ }
1165
+ /* Work on whole document or just its body */
1166
+
1167
+
1168
+ if (NAMESPACE === HTML_NAMESPACE) {
1169
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1170
+ }
1171
+
1172
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1173
+ };
1174
+ /**
1175
+ * _createIterator
1176
+ *
1177
+ * @param {Document} root document/fragment to create iterator for
1178
+ * @return {Iterator} iterator instance
1179
+ */
1180
+
1181
+
1182
+ const _createIterator = function _createIterator(root) {
1183
+ return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
1184
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
1185
+ };
1186
+ /**
1187
+ * _isClobbered
1188
+ *
1189
+ * @param {Node} elm element to check for clobbering attacks
1190
+ * @return {Boolean} true if clobbered, false if safe
1191
+ */
1192
+
1193
+
1194
+ const _isClobbered = function _isClobbered(elm) {
1195
+ return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
1196
+ };
1197
+ /**
1198
+ * _isNode
1199
+ *
1200
+ * @param {Node} obj object to check whether it's a DOM node
1201
+ * @return {Boolean} true is object is a DOM node
1202
+ */
1203
+
1204
+
1205
+ const _isNode = function _isNode(object) {
1206
+ return typeof Node === 'object' ? object instanceof Node : object && typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
1207
+ };
1208
+ /**
1209
+ * _executeHook
1210
+ * Execute user configurable hooks
1211
+ *
1212
+ * @param {String} entryPoint Name of the hook's entry point
1213
+ * @param {Node} currentNode node to work on with the hook
1214
+ * @param {Object} data additional hook parameters
1215
+ */
1216
+
1217
+
1218
+ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
1219
+ if (!hooks[entryPoint]) {
1220
+ return;
1221
+ }
1222
+
1223
+ arrayForEach(hooks[entryPoint], hook => {
1224
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1225
+ });
1226
+ };
1227
+ /**
1228
+ * _sanitizeElements
1229
+ *
1230
+ * @protect nodeName
1231
+ * @protect textContent
1232
+ * @protect removeChild
1233
+ *
1234
+ * @param {Node} currentNode to check for permission to exist
1235
+ * @return {Boolean} true if node was killed, false if left alive
1236
+ */
1237
+
1238
+
1239
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
1240
+ let content;
1241
+ /* Execute a hook if present */
1242
+
1243
+ _executeHook('beforeSanitizeElements', currentNode, null);
1244
+ /* Check if element is clobbered or can clobber */
1245
+
1246
+
1247
+ if (_isClobbered(currentNode)) {
1248
+ _forceRemove(currentNode);
1249
+
1250
+ return true;
1251
+ }
1252
+ /* Now let's check the element's type and name */
1253
+
1254
+
1255
+ const tagName = transformCaseFunc(currentNode.nodeName);
1256
+ /* Execute a hook if present */
1257
+
1258
+ _executeHook('uponSanitizeElement', currentNode, {
1259
+ tagName,
1260
+ allowedTags: ALLOWED_TAGS
1261
+ });
1262
+ /* Detect mXSS attempts abusing namespace confusion */
1263
+
1264
+
1265
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1266
+ _forceRemove(currentNode);
1267
+
1268
+ return true;
1269
+ }
1270
+ /* Remove element if anything forbids its presence */
1271
+
1272
+
1273
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1274
+ /* Check if we have a custom element to handle */
1275
+ if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1276
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1277
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1278
+ }
1279
+ /* Keep content except for bad-listed elements */
1280
+
1281
+
1282
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1283
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1284
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1285
+
1286
+ if (childNodes && parentNode) {
1287
+ const childCount = childNodes.length;
1288
+
1289
+ for (let i = childCount - 1; i >= 0; --i) {
1290
+ parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1291
+ }
1292
+ }
1293
+ }
1294
+
1295
+ _forceRemove(currentNode);
1296
+
1297
+ return true;
1298
+ }
1299
+ /* Check whether element has a valid namespace */
1300
+
1301
+
1302
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1303
+ _forceRemove(currentNode);
1304
+
1305
+ return true;
1306
+ }
1307
+ /* Make sure that older browsers don't get noscript mXSS */
1308
+
1309
+
1310
+ if ((tagName === 'noscript' || tagName === 'noembed') && regExpTest(/<\/no(script|embed)/i, currentNode.innerHTML)) {
1311
+ _forceRemove(currentNode);
1312
+
1313
+ return true;
1314
+ }
1315
+ /* Sanitize element content to be template-safe */
1316
+
1317
+
1318
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1319
+ /* Get the element's text content */
1320
+ content = currentNode.textContent;
1321
+ content = stringReplace(content, MUSTACHE_EXPR, ' ');
1322
+ content = stringReplace(content, ERB_EXPR, ' ');
1323
+ content = stringReplace(content, TMPLIT_EXPR, ' ');
1324
+
1325
+ if (currentNode.textContent !== content) {
1326
+ arrayPush(DOMPurify.removed, {
1327
+ element: currentNode.cloneNode()
1328
+ });
1329
+ currentNode.textContent = content;
1330
+ }
1331
+ }
1332
+ /* Execute a hook if present */
1333
+
1334
+
1335
+ _executeHook('afterSanitizeElements', currentNode, null);
1336
+
1337
+ return false;
1338
+ };
1339
+ /**
1340
+ * _isValidAttribute
1341
+ *
1342
+ * @param {string} lcTag Lowercase tag name of containing element.
1343
+ * @param {string} lcName Lowercase attribute name.
1344
+ * @param {string} value Attribute value.
1345
+ * @return {Boolean} Returns true if `value` is valid, otherwise false.
1346
+ */
1347
+ // eslint-disable-next-line complexity
1348
+
1349
+
1350
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1351
+ /* Make sure attribute cannot clobber */
1352
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1353
+ return false;
1354
+ }
1355
+ /* Allow valid data-* attributes: At least one character after "-"
1356
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1357
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1358
+ We don't need to check the value; it's always URI safe. */
1359
+
1360
+
1361
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1362
+ if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1363
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1364
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1365
+ _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
1366
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1367
+ 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 {
1368
+ return false;
1369
+ }
1370
+ /* Check value is safe. First, is attr inert? If so, is safe */
1371
+
1372
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; 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, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1373
+ return false;
1374
+ } else ;
1375
+
1376
+ return true;
1377
+ };
1378
+ /**
1379
+ * _basicCustomElementCheck
1380
+ * checks if at least one dash is included in tagName, and it's not the first char
1381
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1382
+ * @param {string} tagName name of the tag of the node to sanitize
1383
+ */
1384
+
1385
+
1386
+ const _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1387
+ return tagName.indexOf('-') > 0;
1388
+ };
1389
+ /**
1390
+ * _sanitizeAttributes
1391
+ *
1392
+ * @protect attributes
1393
+ * @protect nodeName
1394
+ * @protect removeAttribute
1395
+ * @protect setAttribute
1396
+ *
1397
+ * @param {Node} currentNode to sanitize
1398
+ */
1399
+
1400
+
1401
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1402
+ let attr;
1403
+ let value;
1404
+ let lcName;
1405
+ let l;
1406
+ /* Execute a hook if present */
1407
+
1408
+ _executeHook('beforeSanitizeAttributes', currentNode, null);
1409
+
1410
+ const {
1411
+ attributes
1412
+ } = currentNode;
1413
+ /* Check if we have attributes; if not we might have a text node */
1414
+
1415
+ if (!attributes) {
1416
+ return;
1417
+ }
1418
+
1419
+ const hookEvent = {
1420
+ attrName: '',
1421
+ attrValue: '',
1422
+ keepAttr: true,
1423
+ allowedAttributes: ALLOWED_ATTR
1424
+ };
1425
+ l = attributes.length;
1426
+ /* Go backwards over all attributes; safely remove bad ones */
1427
+
1428
+ while (l--) {
1429
+ attr = attributes[l];
1430
+ const {
1431
+ name,
1432
+ namespaceURI
1433
+ } = attr;
1434
+ value = name === 'value' ? attr.value : stringTrim(attr.value);
1435
+ lcName = transformCaseFunc(name);
1436
+ /* Execute a hook if present */
1437
+
1438
+ hookEvent.attrName = lcName;
1439
+ hookEvent.attrValue = value;
1440
+ hookEvent.keepAttr = true;
1441
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1442
+
1443
+ _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1444
+
1445
+ value = hookEvent.attrValue;
1446
+ /* Did the hooks approve of the attribute? */
1447
+
1448
+ if (hookEvent.forceKeepAttr) {
1449
+ continue;
1450
+ }
1451
+ /* Remove attribute */
1452
+
1453
+
1454
+ _removeAttribute(name, currentNode);
1455
+ /* Did the hooks approve of the attribute? */
1456
+
1457
+
1458
+ if (!hookEvent.keepAttr) {
1459
+ continue;
1460
+ }
1461
+ /* Work around a security issue in jQuery 3.0 */
1462
+
1463
+
1464
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1465
+ _removeAttribute(name, currentNode);
1466
+
1467
+ continue;
1468
+ }
1469
+ /* Sanitize attribute content to be template-safe */
1470
+
1471
+
1472
+ if (SAFE_FOR_TEMPLATES) {
1473
+ value = stringReplace(value, MUSTACHE_EXPR, ' ');
1474
+ value = stringReplace(value, ERB_EXPR, ' ');
1475
+ value = stringReplace(value, TMPLIT_EXPR, ' ');
1476
+ }
1477
+ /* Is `value` valid for this attribute? */
1478
+
1479
+
1480
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1481
+
1482
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1483
+ continue;
1484
+ }
1485
+ /* Full DOM Clobbering protection via namespace isolation,
1486
+ * Prefix id and name attributes with `user-content-`
1487
+ */
1488
+
1489
+
1490
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1491
+ // Remove the attribute with this value
1492
+ _removeAttribute(name, currentNode); // Prefix the value and later re-create the attribute with the sanitized value
1493
+
1494
+
1495
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1496
+ }
1497
+ /* Handle attributes that require Trusted Types */
1498
+
1499
+
1500
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1501
+ if (namespaceURI) ; else {
1502
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1503
+ case 'TrustedHTML':
1504
+ {
1505
+ value = trustedTypesPolicy.createHTML(value);
1506
+ break;
1507
+ }
1508
+
1509
+ case 'TrustedScriptURL':
1510
+ {
1511
+ value = trustedTypesPolicy.createScriptURL(value);
1512
+ break;
1513
+ }
1514
+ }
1515
+ }
1516
+ }
1517
+ /* Handle invalid data-* attribute set by try-catching it */
1518
+
1519
+
1520
+ try {
1521
+ if (namespaceURI) {
1522
+ currentNode.setAttributeNS(namespaceURI, name, value);
1523
+ } else {
1524
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1525
+ currentNode.setAttribute(name, value);
1526
+ }
1527
+
1528
+ arrayPop(DOMPurify.removed);
1529
+ } catch (_) {}
1530
+ }
1531
+ /* Execute a hook if present */
1532
+
1533
+
1534
+ _executeHook('afterSanitizeAttributes', currentNode, null);
1535
+ };
1536
+ /**
1537
+ * _sanitizeShadowDOM
1538
+ *
1539
+ * @param {DocumentFragment} fragment to iterate over recursively
1540
+ */
1541
+
1542
+
1543
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1544
+ let shadowNode;
1545
+
1546
+ const shadowIterator = _createIterator(fragment);
1547
+ /* Execute a hook if present */
1548
+
1549
+
1550
+ _executeHook('beforeSanitizeShadowDOM', fragment, null);
1551
+
1552
+ while (shadowNode = shadowIterator.nextNode()) {
1553
+ /* Execute a hook if present */
1554
+ _executeHook('uponSanitizeShadowNode', shadowNode, null);
1555
+ /* Sanitize tags and elements */
1556
+
1557
+
1558
+ if (_sanitizeElements(shadowNode)) {
1559
+ continue;
1560
+ }
1561
+ /* Deep shadow DOM detected */
1562
+
1563
+
1564
+ if (shadowNode.content instanceof DocumentFragment) {
1565
+ _sanitizeShadowDOM(shadowNode.content);
1566
+ }
1567
+ /* Check attributes, sanitize if necessary */
1568
+
1569
+
1570
+ _sanitizeAttributes(shadowNode);
1571
+ }
1572
+ /* Execute a hook if present */
1573
+
1574
+
1575
+ _executeHook('afterSanitizeShadowDOM', fragment, null);
1576
+ };
1577
+ /**
1578
+ * Sanitize
1579
+ * Public method providing core sanitation functionality
1580
+ *
1581
+ * @param {String|Node} dirty string or DOM node
1582
+ * @param {Object} configuration object
1583
+ */
1584
+ // eslint-disable-next-line complexity
1585
+
1586
+
1587
+ DOMPurify.sanitize = function (dirty) {
1588
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1589
+ let body;
1590
+ let importedNode;
1591
+ let currentNode;
1592
+ let returnNode;
1593
+ /* Make sure we have a string to sanitize.
1594
+ DO NOT return early, as this will return the wrong type if
1595
+ the user has requested a DOM object rather than a string */
1596
+
1597
+ IS_EMPTY_INPUT = !dirty;
1598
+
1599
+ if (IS_EMPTY_INPUT) {
1600
+ dirty = '<!-->';
1601
+ }
1602
+ /* Stringify, in case dirty is an object */
1603
+
1604
+
1605
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1606
+ if (typeof dirty.toString === 'function') {
1607
+ dirty = dirty.toString();
1608
+
1609
+ if (typeof dirty !== 'string') {
1610
+ throw typeErrorCreate('dirty is not a string, aborting');
1611
+ }
1612
+ } else {
1613
+ throw typeErrorCreate('toString is not a function');
1614
+ }
1615
+ }
1616
+ /* Return dirty HTML if DOMPurify cannot run */
1617
+
1618
+
1619
+ if (!DOMPurify.isSupported) {
1620
+ return dirty;
1621
+ }
1622
+ /* Assign config vars */
1623
+
1624
+
1625
+ if (!SET_CONFIG) {
1626
+ _parseConfig(cfg);
1627
+ }
1628
+ /* Clean up removed elements */
1629
+
1630
+
1631
+ DOMPurify.removed = [];
1632
+ /* Check if dirty is correctly typed for IN_PLACE */
1633
+
1634
+ if (typeof dirty === 'string') {
1635
+ IN_PLACE = false;
1636
+ }
1637
+
1638
+ if (IN_PLACE) {
1639
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1640
+ if (dirty.nodeName) {
1641
+ const tagName = transformCaseFunc(dirty.nodeName);
1642
+
1643
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1644
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1645
+ }
1646
+ }
1647
+ } else if (dirty instanceof Node) {
1648
+ /* If dirty is a DOM element, append to an empty document to avoid
1649
+ elements being stripped by the parser */
1650
+ body = _initDocument('<!---->');
1651
+ importedNode = body.ownerDocument.importNode(dirty, true);
1652
+
1653
+ if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1654
+ /* Node is already a body, use as is */
1655
+ body = importedNode;
1656
+ } else if (importedNode.nodeName === 'HTML') {
1657
+ body = importedNode;
1658
+ } else {
1659
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1660
+ body.appendChild(importedNode);
1661
+ }
1662
+ } else {
1663
+ /* Exit directly if we have nothing to do */
1664
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1665
+ dirty.indexOf('<') === -1) {
1666
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1667
+ }
1668
+ /* Initialize the document to work on */
1669
+
1670
+
1671
+ body = _initDocument(dirty);
1672
+ /* Check we have a DOM node from the data */
1673
+
1674
+ if (!body) {
1675
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1676
+ }
1677
+ }
1678
+ /* Remove first element node (ours) if FORCE_BODY is set */
1679
+
1680
+
1681
+ if (body && FORCE_BODY) {
1682
+ _forceRemove(body.firstChild);
1683
+ }
1684
+ /* Get node iterator */
1685
+
1686
+
1687
+ const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1688
+ /* Now start iterating over the created document */
1689
+
1690
+
1691
+ while (currentNode = nodeIterator.nextNode()) {
1692
+ /* Sanitize tags and elements */
1693
+ if (_sanitizeElements(currentNode)) {
1694
+ continue;
1695
+ }
1696
+ /* Shadow DOM detected, sanitize it */
1697
+
1698
+
1699
+ if (currentNode.content instanceof DocumentFragment) {
1700
+ _sanitizeShadowDOM(currentNode.content);
1701
+ }
1702
+ /* Check attributes, sanitize if necessary */
1703
+
1704
+
1705
+ _sanitizeAttributes(currentNode);
1706
+ }
1707
+ /* If we sanitized `dirty` in-place, return it. */
1708
+
1709
+
1710
+ if (IN_PLACE) {
1711
+ return dirty;
1712
+ }
1713
+ /* Return sanitized string or DOM */
1714
+
1715
+
1716
+ if (RETURN_DOM) {
1717
+ if (RETURN_DOM_FRAGMENT) {
1718
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1719
+
1720
+ while (body.firstChild) {
1721
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1722
+ returnNode.appendChild(body.firstChild);
1723
+ }
1724
+ } else {
1725
+ returnNode = body;
1726
+ }
1727
+
1728
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmod) {
1729
+ /*
1730
+ AdoptNode() is not used because internal state is not reset
1731
+ (e.g. the past names map of a HTMLFormElement), this is safe
1732
+ in theory but we would rather not risk another attack vector.
1733
+ The state that is cloned by importNode() is explicitly defined
1734
+ by the specs.
1735
+ */
1736
+ returnNode = importNode.call(originalDocument, returnNode, true);
1737
+ }
1738
+
1739
+ return returnNode;
1740
+ }
1741
+
1742
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1743
+ /* Serialize doctype if allowed */
1744
+
1745
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1746
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1747
+ }
1748
+ /* Sanitize final string template-safe */
1749
+
1750
+
1751
+ if (SAFE_FOR_TEMPLATES) {
1752
+ serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');
1753
+ serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');
1754
+ serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');
1755
+ }
1756
+
1757
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1758
+ };
1759
+ /**
1760
+ * Public method to set the configuration once
1761
+ * setConfig
1762
+ *
1763
+ * @param {Object} cfg configuration object
1764
+ */
1765
+
1766
+
1767
+ DOMPurify.setConfig = function (cfg) {
1768
+ _parseConfig(cfg);
1769
+
1770
+ SET_CONFIG = true;
1771
+ };
1772
+ /**
1773
+ * Public method to remove the configuration
1774
+ * clearConfig
1775
+ *
1776
+ */
1777
+
1778
+
1779
+ DOMPurify.clearConfig = function () {
1780
+ CONFIG = null;
1781
+ SET_CONFIG = false;
1782
+ };
1783
+ /**
1784
+ * Public method to check if an attribute value is valid.
1785
+ * Uses last set config, if any. Otherwise, uses config defaults.
1786
+ * isValidAttribute
1787
+ *
1788
+ * @param {string} tag Tag name of containing element.
1789
+ * @param {string} attr Attribute name.
1790
+ * @param {string} value Attribute value.
1791
+ * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1792
+ */
1793
+
1794
+
1795
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1796
+ /* Initialize shared config vars if necessary. */
1797
+ if (!CONFIG) {
1798
+ _parseConfig({});
1799
+ }
1800
+
1801
+ const lcTag = transformCaseFunc(tag);
1802
+ const lcName = transformCaseFunc(attr);
1803
+ return _isValidAttribute(lcTag, lcName, value);
1804
+ };
1805
+ /**
1806
+ * AddHook
1807
+ * Public method to add DOMPurify hooks
1808
+ *
1809
+ * @param {String} entryPoint entry point for the hook to add
1810
+ * @param {Function} hookFunction function to execute
1811
+ */
1812
+
1813
+
1814
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1815
+ if (typeof hookFunction !== 'function') {
1816
+ return;
1817
+ }
1818
+
1819
+ hooks[entryPoint] = hooks[entryPoint] || [];
1820
+ arrayPush(hooks[entryPoint], hookFunction);
1821
+ };
1822
+ /**
1823
+ * RemoveHook
1824
+ * Public method to remove a DOMPurify hook at a given entryPoint
1825
+ * (pops it from the stack of hooks if more are present)
1826
+ *
1827
+ * @param {String} entryPoint entry point for the hook to remove
1828
+ * @return {Function} removed(popped) hook
1829
+ */
1830
+
1831
+
1832
+ DOMPurify.removeHook = function (entryPoint) {
1833
+ if (hooks[entryPoint]) {
1834
+ return arrayPop(hooks[entryPoint]);
1835
+ }
1836
+ };
1837
+ /**
1838
+ * RemoveHooks
1839
+ * Public method to remove all DOMPurify hooks at a given entryPoint
1840
+ *
1841
+ * @param {String} entryPoint entry point for the hooks to remove
1842
+ */
1843
+
1844
+
1845
+ DOMPurify.removeHooks = function (entryPoint) {
1846
+ if (hooks[entryPoint]) {
1847
+ hooks[entryPoint] = [];
1848
+ }
1849
+ };
1850
+ /**
1851
+ * RemoveAllHooks
1852
+ * Public method to remove all DOMPurify hooks
1853
+ *
1854
+ */
1855
+
1856
+
1857
+ DOMPurify.removeAllHooks = function () {
1858
+ hooks = {};
1859
+ };
1860
+
1861
+ return DOMPurify;
1862
+ }
1863
+
1864
+ var purify = createDOMPurify();
1865
+
243
1866
  var generic = {
244
1867
  error: "Something went wrong. Please try again later."
245
1868
  };
@@ -600,17 +2223,23 @@ var commonsEn = {
600
2223
  neetoCommons: neetoCommons
601
2224
  };
602
2225
 
603
- var loadEn = function loadEn(pkgName) {
604
- try {
605
- return require("../".concat(pkgName, "/src/translations/en.json"));
606
- } catch (_unused) {
607
- return {};
608
- }
2226
+ var packageNames = ["neeto-molecules", "neeto-team-members-frontend"];
2227
+ var getPackageTranslations = function getPackageTranslations(language, packageNames) {
2228
+ var loadTranslations = curry(function (language, packageName) {
2229
+ try {
2230
+ return require("../".concat(packageName, "/src/translations/").concat(language, ".json"));
2231
+ } catch (_unused) {
2232
+ return {};
2233
+ }
2234
+ });
2235
+ var allTranslations = packageNames.map(loadTranslations(language));
2236
+ return mergeAll(allTranslations);
609
2237
  };
610
- var moleculesEn = loadEn("neeto-molecules");
611
- var en = mergeDeepLeft(commonsEn, moleculesEn);
2238
+ var packageEnTranslations = getPackageTranslations("en", packageNames);
2239
+ var en = mergeDeepLeft(commonsEn, packageEnTranslations);
612
2240
  var initializeI18n = function initializeI18n(resources) {
613
- i18next.use(initReactI18next).init({
2241
+ var _i18n$services$format;
2242
+ i18n.use(initReactI18next).init({
614
2243
  resources: mergeDeepLeft(resources, {
615
2244
  en: {
616
2245
  translation: en
@@ -623,6 +2252,23 @@ var initializeI18n = function initializeI18n(resources) {
623
2252
  skipOnVariables: false
624
2253
  }
625
2254
  });
2255
+ (_i18n$services$format = i18n.services.formatter) === null || _i18n$services$format === void 0 ? void 0 : _i18n$services$format.addCached("boldList", function (language, options) {
2256
+ var formatter = new Intl.ListFormat(language, options);
2257
+ var sanitizer = function sanitizer(array) {
2258
+ return purify.sanitize(array, {
2259
+ USE_PROFILES: {
2260
+ html: true
2261
+ }
2262
+ });
2263
+ };
2264
+ return function (array) {
2265
+ var boldItems = array.map(function (item) {
2266
+ return "<strong>".concat(item, "</strong>");
2267
+ });
2268
+ var sanitizedItems = sanitizer(boldItems).split(",");
2269
+ return formatter.format(sanitizedItems);
2270
+ };
2271
+ });
626
2272
  };
627
2273
 
628
2274
  function initializeLogger() {