@wiris/mathtype-ckeditor5 8.11.1 → 8.12.0

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.
@@ -3,1954 +3,1335 @@ import { ButtonView } from 'ckeditor5';
3
3
  import { ClickObserver, XmlDataProcessor, UpcastWriter, HtmlDataProcessor } from 'ckeditor5';
4
4
  import { Widget, viewToModelPositionOutsideModelElement, toWidget } from 'ckeditor5';
5
5
 
6
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
+ /*! @license DOMPurify 3.2.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.2.3/LICENSE */
7
7
 
8
- var purify = {exports: {}};
8
+ const {
9
+ entries,
10
+ setPrototypeOf,
11
+ isFrozen,
12
+ getPrototypeOf,
13
+ getOwnPropertyDescriptor
14
+ } = Object;
15
+ let {
16
+ freeze,
17
+ seal,
18
+ create
19
+ } = Object; // eslint-disable-line import/no-mutable-exports
20
+ let {
21
+ apply,
22
+ construct
23
+ } = typeof Reflect !== 'undefined' && Reflect;
24
+ if (!freeze) {
25
+ freeze = function freeze(x) {
26
+ return x;
27
+ };
28
+ }
29
+ if (!seal) {
30
+ seal = function seal(x) {
31
+ return x;
32
+ };
33
+ }
34
+ if (!apply) {
35
+ apply = function apply(fun, thisValue, args) {
36
+ return fun.apply(thisValue, args);
37
+ };
38
+ }
39
+ if (!construct) {
40
+ construct = function construct(Func, args) {
41
+ return new Func(...args);
42
+ };
43
+ }
44
+ const arrayForEach = unapply(Array.prototype.forEach);
45
+ const arrayPop = unapply(Array.prototype.pop);
46
+ const arrayPush = unapply(Array.prototype.push);
47
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
48
+ const stringToString = unapply(String.prototype.toString);
49
+ const stringMatch = unapply(String.prototype.match);
50
+ const stringReplace = unapply(String.prototype.replace);
51
+ const stringIndexOf = unapply(String.prototype.indexOf);
52
+ const stringTrim = unapply(String.prototype.trim);
53
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
54
+ const regExpTest = unapply(RegExp.prototype.test);
55
+ const typeErrorCreate = unconstruct(TypeError);
56
+ /**
57
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
58
+ *
59
+ * @param func - The function to be wrapped and called.
60
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
61
+ */
62
+ function unapply(func) {
63
+ return function (thisArg) {
64
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
65
+ args[_key - 1] = arguments[_key];
66
+ }
67
+ return apply(func, thisArg, args);
68
+ };
69
+ }
70
+ /**
71
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
72
+ *
73
+ * @param func - The constructor function to be wrapped and called.
74
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
75
+ */
76
+ function unconstruct(func) {
77
+ return function () {
78
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
79
+ args[_key2] = arguments[_key2];
80
+ }
81
+ return construct(func, args);
82
+ };
83
+ }
84
+ /**
85
+ * Add properties to a lookup table
86
+ *
87
+ * @param set - The set to which elements will be added.
88
+ * @param array - The array containing elements to be added to the set.
89
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
90
+ * @returns The modified set with added elements.
91
+ */
92
+ function addToSet(set, array) {
93
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
94
+ if (setPrototypeOf) {
95
+ // Make 'in' and truthy checks like Boolean(set.constructor)
96
+ // independent of any properties defined on Object.prototype.
97
+ // Prevent prototype setters from intercepting set as a this value.
98
+ setPrototypeOf(set, null);
99
+ }
100
+ let l = array.length;
101
+ while (l--) {
102
+ let element = array[l];
103
+ if (typeof element === 'string') {
104
+ const lcElement = transformCaseFunc(element);
105
+ if (lcElement !== element) {
106
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
107
+ if (!isFrozen(array)) {
108
+ array[l] = lcElement;
109
+ }
110
+ element = lcElement;
111
+ }
112
+ }
113
+ set[element] = true;
114
+ }
115
+ return set;
116
+ }
117
+ /**
118
+ * Clean up an array to harden against CSPP
119
+ *
120
+ * @param array - The array to be cleaned.
121
+ * @returns The cleaned version of the array
122
+ */
123
+ function cleanArray(array) {
124
+ for (let index = 0; index < array.length; index++) {
125
+ const isPropertyExist = objectHasOwnProperty(array, index);
126
+ if (!isPropertyExist) {
127
+ array[index] = null;
128
+ }
129
+ }
130
+ return array;
131
+ }
132
+ /**
133
+ * Shallow clone an object
134
+ *
135
+ * @param object - The object to be cloned.
136
+ * @returns A new object that copies the original.
137
+ */
138
+ function clone(object) {
139
+ const newObject = create(null);
140
+ for (const [property, value] of entries(object)) {
141
+ const isPropertyExist = objectHasOwnProperty(object, property);
142
+ if (isPropertyExist) {
143
+ if (Array.isArray(value)) {
144
+ newObject[property] = cleanArray(value);
145
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
146
+ newObject[property] = clone(value);
147
+ } else {
148
+ newObject[property] = value;
149
+ }
150
+ }
151
+ }
152
+ return newObject;
153
+ }
154
+ /**
155
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
156
+ *
157
+ * @param object - The object to look up the getter function in its prototype chain.
158
+ * @param prop - The property name for which to find the getter function.
159
+ * @returns The getter function found in the prototype chain or a fallback function.
160
+ */
161
+ function lookupGetter(object, prop) {
162
+ while (object !== null) {
163
+ const desc = getOwnPropertyDescriptor(object, prop);
164
+ if (desc) {
165
+ if (desc.get) {
166
+ return unapply(desc.get);
167
+ }
168
+ if (typeof desc.value === 'function') {
169
+ return unapply(desc.value);
170
+ }
171
+ }
172
+ object = getPrototypeOf(object);
173
+ }
174
+ function fallbackValue() {
175
+ return null;
176
+ }
177
+ return fallbackValue;
178
+ }
9
179
 
10
- (function(module, exports) {
11
- (function(global, factory) {
12
- module.exports = factory() ;
13
- })(commonjsGlobal, function() {
14
- const { entries, setPrototypeOf, isFrozen, getPrototypeOf, getOwnPropertyDescriptor } = Object;
15
- let { freeze, seal, create } = Object; // eslint-disable-line import/no-mutable-exports
16
- let { apply, construct } = typeof Reflect !== 'undefined' && Reflect;
17
- if (!freeze) {
18
- freeze = function freeze(x) {
19
- return x;
20
- };
21
- }
22
- if (!seal) {
23
- seal = function seal(x) {
24
- return x;
25
- };
26
- }
27
- if (!apply) {
28
- apply = function apply(fun, thisValue, args) {
29
- return fun.apply(thisValue, args);
30
- };
31
- }
32
- if (!construct) {
33
- construct = function construct(Func, args) {
34
- return new Func(...args);
35
- };
36
- }
37
- const arrayForEach = unapply(Array.prototype.forEach);
38
- const arrayPop = unapply(Array.prototype.pop);
39
- const arrayPush = unapply(Array.prototype.push);
40
- const stringToLowerCase = unapply(String.prototype.toLowerCase);
41
- const stringToString = unapply(String.prototype.toString);
42
- const stringMatch = unapply(String.prototype.match);
43
- const stringReplace = unapply(String.prototype.replace);
44
- const stringIndexOf = unapply(String.prototype.indexOf);
45
- const stringTrim = unapply(String.prototype.trim);
46
- const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
47
- const regExpTest = unapply(RegExp.prototype.test);
48
- const typeErrorCreate = unconstruct(TypeError);
49
- /**
50
- * Creates a new function that calls the given function with a specified thisArg and arguments.
51
- *
52
- * @param {Function} func - The function to be wrapped and called.
53
- * @returns {Function} A new function that calls the given function with a specified thisArg and arguments.
54
- */ function unapply(func) {
55
- return function(thisArg) {
56
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
57
- args[_key - 1] = arguments[_key];
58
- }
59
- return apply(func, thisArg, args);
60
- };
61
- }
62
- /**
63
- * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
64
- *
65
- * @param {Function} func - The constructor function to be wrapped and called.
66
- * @returns {Function} A new function that constructs an instance of the given constructor function with the provided arguments.
67
- */ function unconstruct(func) {
68
- return function() {
69
- for(var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++){
70
- args[_key2] = arguments[_key2];
71
- }
72
- return construct(func, args);
73
- };
74
- }
75
- /**
76
- * Add properties to a lookup table
77
- *
78
- * @param {Object} set - The set to which elements will be added.
79
- * @param {Array} array - The array containing elements to be added to the set.
80
- * @param {Function} transformCaseFunc - An optional function to transform the case of each element before adding to the set.
81
- * @returns {Object} The modified set with added elements.
82
- */ function addToSet(set, array) {
83
- let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
84
- if (setPrototypeOf) {
85
- // Make 'in' and truthy checks like Boolean(set.constructor)
86
- // independent of any properties defined on Object.prototype.
87
- // Prevent prototype setters from intercepting set as a this value.
88
- setPrototypeOf(set, null);
89
- }
90
- let l = array.length;
91
- while(l--){
92
- let element = array[l];
93
- if (typeof element === 'string') {
94
- const lcElement = transformCaseFunc(element);
95
- if (lcElement !== element) {
96
- // Config presets (e.g. tags.js, attrs.js) are immutable.
97
- if (!isFrozen(array)) {
98
- array[l] = lcElement;
99
- }
100
- element = lcElement;
101
- }
102
- }
103
- set[element] = true;
104
- }
105
- return set;
106
- }
107
- /**
108
- * Clean up an array to harden against CSPP
109
- *
110
- * @param {Array} array - The array to be cleaned.
111
- * @returns {Array} The cleaned version of the array
112
- */ function cleanArray(array) {
113
- for(let index = 0; index < array.length; index++){
114
- const isPropertyExist = objectHasOwnProperty(array, index);
115
- if (!isPropertyExist) {
116
- array[index] = null;
117
- }
118
- }
119
- return array;
120
- }
121
- /**
122
- * Shallow clone an object
123
- *
124
- * @param {Object} object - The object to be cloned.
125
- * @returns {Object} A new object that copies the original.
126
- */ function clone(object) {
127
- const newObject = create(null);
128
- for (const [property, value] of entries(object)){
129
- const isPropertyExist = objectHasOwnProperty(object, property);
130
- if (isPropertyExist) {
131
- if (Array.isArray(value)) {
132
- newObject[property] = cleanArray(value);
133
- } else if (value && typeof value === 'object' && value.constructor === Object) {
134
- newObject[property] = clone(value);
135
- } else {
136
- newObject[property] = value;
137
- }
138
- }
139
- }
140
- return newObject;
141
- }
142
- /**
143
- * This method automatically checks if the prop is function or getter and behaves accordingly.
144
- *
145
- * @param {Object} object - The object to look up the getter function in its prototype chain.
146
- * @param {String} prop - The property name for which to find the getter function.
147
- * @returns {Function} The getter function found in the prototype chain or a fallback function.
148
- */ function lookupGetter(object, prop) {
149
- while(object !== null){
150
- const desc = getOwnPropertyDescriptor(object, prop);
151
- if (desc) {
152
- if (desc.get) {
153
- return unapply(desc.get);
154
- }
155
- if (typeof desc.value === 'function') {
156
- return unapply(desc.value);
157
- }
158
- }
159
- object = getPrototypeOf(object);
160
- }
161
- function fallbackValue() {
162
- return null;
163
- }
164
- return fallbackValue;
165
- }
166
- const html$1 = freeze([
167
- 'a',
168
- 'abbr',
169
- 'acronym',
170
- 'address',
171
- 'area',
172
- 'article',
173
- 'aside',
174
- 'audio',
175
- 'b',
176
- 'bdi',
177
- 'bdo',
178
- 'big',
179
- 'blink',
180
- 'blockquote',
181
- 'body',
182
- 'br',
183
- 'button',
184
- 'canvas',
185
- 'caption',
186
- 'center',
187
- 'cite',
188
- 'code',
189
- 'col',
190
- 'colgroup',
191
- 'content',
192
- 'data',
193
- 'datalist',
194
- 'dd',
195
- 'decorator',
196
- 'del',
197
- 'details',
198
- 'dfn',
199
- 'dialog',
200
- 'dir',
201
- 'div',
202
- 'dl',
203
- 'dt',
204
- 'element',
205
- 'em',
206
- 'fieldset',
207
- 'figcaption',
208
- 'figure',
209
- 'font',
210
- 'footer',
211
- 'form',
212
- 'h1',
213
- 'h2',
214
- 'h3',
215
- 'h4',
216
- 'h5',
217
- 'h6',
218
- 'head',
219
- 'header',
220
- 'hgroup',
221
- 'hr',
222
- 'html',
223
- 'i',
224
- 'img',
225
- 'input',
226
- 'ins',
227
- 'kbd',
228
- 'label',
229
- 'legend',
230
- 'li',
231
- 'main',
232
- 'map',
233
- 'mark',
234
- 'marquee',
235
- 'menu',
236
- 'menuitem',
237
- 'meter',
238
- 'nav',
239
- 'nobr',
240
- 'ol',
241
- 'optgroup',
242
- 'option',
243
- 'output',
244
- 'p',
245
- 'picture',
246
- 'pre',
247
- 'progress',
248
- 'q',
249
- 'rp',
250
- 'rt',
251
- 'ruby',
252
- 's',
253
- 'samp',
254
- 'section',
255
- 'select',
256
- 'shadow',
257
- 'small',
258
- 'source',
259
- 'spacer',
260
- 'span',
261
- 'strike',
262
- 'strong',
263
- 'style',
264
- 'sub',
265
- 'summary',
266
- 'sup',
267
- 'table',
268
- 'tbody',
269
- 'td',
270
- 'template',
271
- 'textarea',
272
- 'tfoot',
273
- 'th',
274
- 'thead',
275
- 'time',
276
- 'tr',
277
- 'track',
278
- 'tt',
279
- 'u',
280
- 'ul',
281
- 'var',
282
- 'video',
283
- 'wbr'
284
- ]);
285
- // SVG
286
- const svg$1 = freeze([
287
- 'svg',
288
- 'a',
289
- 'altglyph',
290
- 'altglyphdef',
291
- 'altglyphitem',
292
- 'animatecolor',
293
- 'animatemotion',
294
- 'animatetransform',
295
- 'circle',
296
- 'clippath',
297
- 'defs',
298
- 'desc',
299
- 'ellipse',
300
- 'filter',
301
- 'font',
302
- 'g',
303
- 'glyph',
304
- 'glyphref',
305
- 'hkern',
306
- 'image',
307
- 'line',
308
- 'lineargradient',
309
- 'marker',
310
- 'mask',
311
- 'metadata',
312
- 'mpath',
313
- 'path',
314
- 'pattern',
315
- 'polygon',
316
- 'polyline',
317
- 'radialgradient',
318
- 'rect',
319
- 'stop',
320
- 'style',
321
- 'switch',
322
- 'symbol',
323
- 'text',
324
- 'textpath',
325
- 'title',
326
- 'tref',
327
- 'tspan',
328
- 'view',
329
- 'vkern'
330
- ]);
331
- const svgFilters = freeze([
332
- 'feBlend',
333
- 'feColorMatrix',
334
- 'feComponentTransfer',
335
- 'feComposite',
336
- 'feConvolveMatrix',
337
- 'feDiffuseLighting',
338
- 'feDisplacementMap',
339
- 'feDistantLight',
340
- 'feDropShadow',
341
- 'feFlood',
342
- 'feFuncA',
343
- 'feFuncB',
344
- 'feFuncG',
345
- 'feFuncR',
346
- 'feGaussianBlur',
347
- 'feImage',
348
- 'feMerge',
349
- 'feMergeNode',
350
- 'feMorphology',
351
- 'feOffset',
352
- 'fePointLight',
353
- 'feSpecularLighting',
354
- 'feSpotLight',
355
- 'feTile',
356
- 'feTurbulence'
357
- ]);
358
- // List of SVG elements that are disallowed by default.
359
- // We still need to know them so that we can do namespace
360
- // checks properly in case one wants to add them to
361
- // allow-list.
362
- const svgDisallowed = freeze([
363
- 'animate',
364
- 'color-profile',
365
- 'cursor',
366
- 'discard',
367
- 'font-face',
368
- 'font-face-format',
369
- 'font-face-name',
370
- 'font-face-src',
371
- 'font-face-uri',
372
- 'foreignobject',
373
- 'hatch',
374
- 'hatchpath',
375
- 'mesh',
376
- 'meshgradient',
377
- 'meshpatch',
378
- 'meshrow',
379
- 'missing-glyph',
380
- 'script',
381
- 'set',
382
- 'solidcolor',
383
- 'unknown',
384
- 'use'
385
- ]);
386
- const mathMl$1 = freeze([
387
- 'math',
388
- 'menclose',
389
- 'merror',
390
- 'mfenced',
391
- 'mfrac',
392
- 'mglyph',
393
- 'mi',
394
- 'mlabeledtr',
395
- 'mmultiscripts',
396
- 'mn',
397
- 'mo',
398
- 'mover',
399
- 'mpadded',
400
- 'mphantom',
401
- 'mroot',
402
- 'mrow',
403
- 'ms',
404
- 'mspace',
405
- 'msqrt',
406
- 'mstyle',
407
- 'msub',
408
- 'msup',
409
- 'msubsup',
410
- 'mtable',
411
- 'mtd',
412
- 'mtext',
413
- 'mtr',
414
- 'munder',
415
- 'munderover',
416
- 'mprescripts'
417
- ]);
418
- // Similarly to SVG, we want to know all MathML elements,
419
- // even those that we disallow by default.
420
- const mathMlDisallowed = freeze([
421
- 'maction',
422
- 'maligngroup',
423
- 'malignmark',
424
- 'mlongdiv',
425
- 'mscarries',
426
- 'mscarry',
427
- 'msgroup',
428
- 'mstack',
429
- 'msline',
430
- 'msrow',
431
- 'semantics',
432
- 'annotation',
433
- 'annotation-xml',
434
- 'mprescripts',
435
- 'none'
436
- ]);
437
- const text = freeze([
438
- '#text'
439
- ]);
440
- const html = freeze([
441
- 'accept',
442
- 'action',
443
- 'align',
444
- 'alt',
445
- 'autocapitalize',
446
- 'autocomplete',
447
- 'autopictureinpicture',
448
- 'autoplay',
449
- 'background',
450
- 'bgcolor',
451
- 'border',
452
- 'capture',
453
- 'cellpadding',
454
- 'cellspacing',
455
- 'checked',
456
- 'cite',
457
- 'class',
458
- 'clear',
459
- 'color',
460
- 'cols',
461
- 'colspan',
462
- 'controls',
463
- 'controlslist',
464
- 'coords',
465
- 'crossorigin',
466
- 'datetime',
467
- 'decoding',
468
- 'default',
469
- 'dir',
470
- 'disabled',
471
- 'disablepictureinpicture',
472
- 'disableremoteplayback',
473
- 'download',
474
- 'draggable',
475
- 'enctype',
476
- 'enterkeyhint',
477
- 'face',
478
- 'for',
479
- 'headers',
480
- 'height',
481
- 'hidden',
482
- 'high',
483
- 'href',
484
- 'hreflang',
485
- 'id',
486
- 'inputmode',
487
- 'integrity',
488
- 'ismap',
489
- 'kind',
490
- 'label',
491
- 'lang',
492
- 'list',
493
- 'loading',
494
- 'loop',
495
- 'low',
496
- 'max',
497
- 'maxlength',
498
- 'media',
499
- 'method',
500
- 'min',
501
- 'minlength',
502
- 'multiple',
503
- 'muted',
504
- 'name',
505
- 'nonce',
506
- 'noshade',
507
- 'novalidate',
508
- 'nowrap',
509
- 'open',
510
- 'optimum',
511
- 'pattern',
512
- 'placeholder',
513
- 'playsinline',
514
- 'popover',
515
- 'popovertarget',
516
- 'popovertargetaction',
517
- 'poster',
518
- 'preload',
519
- 'pubdate',
520
- 'radiogroup',
521
- 'readonly',
522
- 'rel',
523
- 'required',
524
- 'rev',
525
- 'reversed',
526
- 'role',
527
- 'rows',
528
- 'rowspan',
529
- 'spellcheck',
530
- 'scope',
531
- 'selected',
532
- 'shape',
533
- 'size',
534
- 'sizes',
535
- 'span',
536
- 'srclang',
537
- 'start',
538
- 'src',
539
- 'srcset',
540
- 'step',
541
- 'style',
542
- 'summary',
543
- 'tabindex',
544
- 'title',
545
- 'translate',
546
- 'type',
547
- 'usemap',
548
- 'valign',
549
- 'value',
550
- 'width',
551
- 'wrap',
552
- 'xmlns',
553
- 'slot'
554
- ]);
555
- const svg = freeze([
556
- 'accent-height',
557
- 'accumulate',
558
- 'additive',
559
- 'alignment-baseline',
560
- 'amplitude',
561
- 'ascent',
562
- 'attributename',
563
- 'attributetype',
564
- 'azimuth',
565
- 'basefrequency',
566
- 'baseline-shift',
567
- 'begin',
568
- 'bias',
569
- 'by',
570
- 'class',
571
- 'clip',
572
- 'clippathunits',
573
- 'clip-path',
574
- 'clip-rule',
575
- 'color',
576
- 'color-interpolation',
577
- 'color-interpolation-filters',
578
- 'color-profile',
579
- 'color-rendering',
580
- 'cx',
581
- 'cy',
582
- 'd',
583
- 'dx',
584
- 'dy',
585
- 'diffuseconstant',
586
- 'direction',
587
- 'display',
588
- 'divisor',
589
- 'dur',
590
- 'edgemode',
591
- 'elevation',
592
- 'end',
593
- 'exponent',
594
- 'fill',
595
- 'fill-opacity',
596
- 'fill-rule',
597
- 'filter',
598
- 'filterunits',
599
- 'flood-color',
600
- 'flood-opacity',
601
- 'font-family',
602
- 'font-size',
603
- 'font-size-adjust',
604
- 'font-stretch',
605
- 'font-style',
606
- 'font-variant',
607
- 'font-weight',
608
- 'fx',
609
- 'fy',
610
- 'g1',
611
- 'g2',
612
- 'glyph-name',
613
- 'glyphref',
614
- 'gradientunits',
615
- 'gradienttransform',
616
- 'height',
617
- 'href',
618
- 'id',
619
- 'image-rendering',
620
- 'in',
621
- 'in2',
622
- 'intercept',
623
- 'k',
624
- 'k1',
625
- 'k2',
626
- 'k3',
627
- 'k4',
628
- 'kerning',
629
- 'keypoints',
630
- 'keysplines',
631
- 'keytimes',
632
- 'lang',
633
- 'lengthadjust',
634
- 'letter-spacing',
635
- 'kernelmatrix',
636
- 'kernelunitlength',
637
- 'lighting-color',
638
- 'local',
639
- 'marker-end',
640
- 'marker-mid',
641
- 'marker-start',
642
- 'markerheight',
643
- 'markerunits',
644
- 'markerwidth',
645
- 'maskcontentunits',
646
- 'maskunits',
647
- 'max',
648
- 'mask',
649
- 'media',
650
- 'method',
651
- 'mode',
652
- 'min',
653
- 'name',
654
- 'numoctaves',
655
- 'offset',
656
- 'operator',
657
- 'opacity',
658
- 'order',
659
- 'orient',
660
- 'orientation',
661
- 'origin',
662
- 'overflow',
663
- 'paint-order',
664
- 'path',
665
- 'pathlength',
666
- 'patterncontentunits',
667
- 'patterntransform',
668
- 'patternunits',
669
- 'points',
670
- 'preservealpha',
671
- 'preserveaspectratio',
672
- 'primitiveunits',
673
- 'r',
674
- 'rx',
675
- 'ry',
676
- 'radius',
677
- 'refx',
678
- 'refy',
679
- 'repeatcount',
680
- 'repeatdur',
681
- 'restart',
682
- 'result',
683
- 'rotate',
684
- 'scale',
685
- 'seed',
686
- 'shape-rendering',
687
- 'slope',
688
- 'specularconstant',
689
- 'specularexponent',
690
- 'spreadmethod',
691
- 'startoffset',
692
- 'stddeviation',
693
- 'stitchtiles',
694
- 'stop-color',
695
- 'stop-opacity',
696
- 'stroke-dasharray',
697
- 'stroke-dashoffset',
698
- 'stroke-linecap',
699
- 'stroke-linejoin',
700
- 'stroke-miterlimit',
701
- 'stroke-opacity',
702
- 'stroke',
703
- 'stroke-width',
704
- 'style',
705
- 'surfacescale',
706
- 'systemlanguage',
707
- 'tabindex',
708
- 'tablevalues',
709
- 'targetx',
710
- 'targety',
711
- 'transform',
712
- 'transform-origin',
713
- 'text-anchor',
714
- 'text-decoration',
715
- 'text-rendering',
716
- 'textlength',
717
- 'type',
718
- 'u1',
719
- 'u2',
720
- 'unicode',
721
- 'values',
722
- 'viewbox',
723
- 'visibility',
724
- 'version',
725
- 'vert-adv-y',
726
- 'vert-origin-x',
727
- 'vert-origin-y',
728
- 'width',
729
- 'word-spacing',
730
- 'wrap',
731
- 'writing-mode',
732
- 'xchannelselector',
733
- 'ychannelselector',
734
- 'x',
735
- 'x1',
736
- 'x2',
737
- 'xmlns',
738
- 'y',
739
- 'y1',
740
- 'y2',
741
- 'z',
742
- 'zoomandpan'
743
- ]);
744
- const mathMl = freeze([
745
- 'accent',
746
- 'accentunder',
747
- 'align',
748
- 'bevelled',
749
- 'close',
750
- 'columnsalign',
751
- 'columnlines',
752
- 'columnspan',
753
- 'denomalign',
754
- 'depth',
755
- 'dir',
756
- 'display',
757
- 'displaystyle',
758
- 'encoding',
759
- 'fence',
760
- 'frame',
761
- 'height',
762
- 'href',
763
- 'id',
764
- 'largeop',
765
- 'length',
766
- 'linethickness',
767
- 'lspace',
768
- 'lquote',
769
- 'mathbackground',
770
- 'mathcolor',
771
- 'mathsize',
772
- 'mathvariant',
773
- 'maxsize',
774
- 'minsize',
775
- 'movablelimits',
776
- 'notation',
777
- 'numalign',
778
- 'open',
779
- 'rowalign',
780
- 'rowlines',
781
- 'rowspacing',
782
- 'rowspan',
783
- 'rspace',
784
- 'rquote',
785
- 'scriptlevel',
786
- 'scriptminsize',
787
- 'scriptsizemultiplier',
788
- 'selection',
789
- 'separator',
790
- 'separators',
791
- 'stretchy',
792
- 'subscriptshift',
793
- 'supscriptshift',
794
- 'symmetric',
795
- 'voffset',
796
- 'width',
797
- 'xmlns'
798
- ]);
799
- const xml = freeze([
800
- 'xlink:href',
801
- 'xml:id',
802
- 'xlink:title',
803
- 'xml:space',
804
- 'xmlns:xlink'
805
- ]);
806
- // eslint-disable-next-line unicorn/better-regex
807
- const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
808
- const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
809
- const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
810
- const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
811
- const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
812
- 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
813
- );
814
- const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
815
- const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
816
- );
817
- const DOCTYPE_NAME = seal(/^html$/i);
818
- const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
819
- var EXPRESSIONS = /*#__PURE__*/ Object.freeze({
820
- __proto__: null,
821
- MUSTACHE_EXPR: MUSTACHE_EXPR,
822
- ERB_EXPR: ERB_EXPR,
823
- TMPLIT_EXPR: TMPLIT_EXPR,
824
- DATA_ATTR: DATA_ATTR,
825
- ARIA_ATTR: ARIA_ATTR,
826
- IS_ALLOWED_URI: IS_ALLOWED_URI,
827
- IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
828
- ATTR_WHITESPACE: ATTR_WHITESPACE,
829
- DOCTYPE_NAME: DOCTYPE_NAME,
830
- CUSTOM_ELEMENT: CUSTOM_ELEMENT
180
+ 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']);
181
+ 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']);
182
+ 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']);
183
+ // List of SVG elements that are disallowed by default.
184
+ // We still need to know them so that we can do namespace
185
+ // checks properly in case one wants to add them to
186
+ // allow-list.
187
+ 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']);
188
+ 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']);
189
+ // Similarly to SVG, we want to know all MathML elements,
190
+ // even those that we disallow by default.
191
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
192
+ const text = freeze(['#text']);
193
+
194
+ 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', 'popover', 'popovertarget', 'popovertargetaction', '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', 'wrap', 'xmlns', 'slot']);
195
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', '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', 'exponent', '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', 'intercept', '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', 'slope', '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', 'tablevalues', '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']);
196
+ 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']);
197
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
198
+
199
+ // eslint-disable-next-line unicorn/better-regex
200
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
201
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
202
+ const TMPLIT_EXPR = seal(/\$\{[\w\W]*}/gm); // eslint-disable-line unicorn/better-regex
203
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
204
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
205
+ 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
206
+ );
207
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
208
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
209
+ );
210
+ const DOCTYPE_NAME = seal(/^html$/i);
211
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
212
+
213
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
214
+ __proto__: null,
215
+ ARIA_ATTR: ARIA_ATTR,
216
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
217
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT,
218
+ DATA_ATTR: DATA_ATTR,
219
+ DOCTYPE_NAME: DOCTYPE_NAME,
220
+ ERB_EXPR: ERB_EXPR,
221
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
222
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
223
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
224
+ TMPLIT_EXPR: TMPLIT_EXPR
225
+ });
226
+
227
+ /* eslint-disable @typescript-eslint/indent */
228
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
229
+ const NODE_TYPE = {
230
+ element: 1,
231
+ attribute: 2,
232
+ text: 3,
233
+ cdataSection: 4,
234
+ entityReference: 5,
235
+ // Deprecated
236
+ entityNode: 6,
237
+ // Deprecated
238
+ progressingInstruction: 7,
239
+ comment: 8,
240
+ document: 9,
241
+ documentType: 10,
242
+ documentFragment: 11,
243
+ notation: 12 // Deprecated
244
+ };
245
+ const getGlobal = function getGlobal() {
246
+ return typeof window === 'undefined' ? null : window;
247
+ };
248
+ /**
249
+ * Creates a no-op policy for internal use only.
250
+ * Don't export this function outside this module!
251
+ * @param trustedTypes The policy factory.
252
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
253
+ * @return The policy created (or null, if Trusted Types
254
+ * are not supported or creating the policy failed).
255
+ */
256
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
257
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
258
+ return null;
259
+ }
260
+ // Allow the callers to control the unique policy name
261
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
262
+ // Policy creation with duplicate names throws in Trusted Types.
263
+ let suffix = null;
264
+ const ATTR_NAME = 'data-tt-policy-suffix';
265
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
266
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
267
+ }
268
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
269
+ try {
270
+ return trustedTypes.createPolicy(policyName, {
271
+ createHTML(html) {
272
+ return html;
273
+ },
274
+ createScriptURL(scriptUrl) {
275
+ return scriptUrl;
276
+ }
277
+ });
278
+ } catch (_) {
279
+ // Policy creation failed (most likely another DOMPurify script has
280
+ // already run). Skip creating the policy, as this will only cause errors
281
+ // if TT are enforced.
282
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
283
+ return null;
284
+ }
285
+ };
286
+ const _createHooksMap = function _createHooksMap() {
287
+ return {
288
+ afterSanitizeAttributes: [],
289
+ afterSanitizeElements: [],
290
+ afterSanitizeShadowDOM: [],
291
+ beforeSanitizeAttributes: [],
292
+ beforeSanitizeElements: [],
293
+ beforeSanitizeShadowDOM: [],
294
+ uponSanitizeAttribute: [],
295
+ uponSanitizeElement: [],
296
+ uponSanitizeShadowNode: []
297
+ };
298
+ };
299
+ function createDOMPurify() {
300
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
301
+ const DOMPurify = root => createDOMPurify(root);
302
+ DOMPurify.version = '3.2.3';
303
+ DOMPurify.removed = [];
304
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document) {
305
+ // Not running in a browser, provide a factory function
306
+ // so that you can pass your own Window
307
+ DOMPurify.isSupported = false;
308
+ return DOMPurify;
309
+ }
310
+ let {
311
+ document
312
+ } = window;
313
+ const originalDocument = document;
314
+ const currentScript = originalDocument.currentScript;
315
+ const {
316
+ DocumentFragment,
317
+ HTMLTemplateElement,
318
+ Node,
319
+ Element,
320
+ NodeFilter,
321
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
322
+ HTMLFormElement,
323
+ DOMParser,
324
+ trustedTypes
325
+ } = window;
326
+ const ElementPrototype = Element.prototype;
327
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
328
+ const remove = lookupGetter(ElementPrototype, 'remove');
329
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
330
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
331
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
332
+ // As per issue #47, the web-components registry is inherited by a
333
+ // new document created via createHTMLDocument. As per the spec
334
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
335
+ // a new empty registry is used when creating a template contents owner
336
+ // document, so we use that as our parent document to ensure nothing
337
+ // is inherited.
338
+ if (typeof HTMLTemplateElement === 'function') {
339
+ const template = document.createElement('template');
340
+ if (template.content && template.content.ownerDocument) {
341
+ document = template.content.ownerDocument;
342
+ }
343
+ }
344
+ let trustedTypesPolicy;
345
+ let emptyHTML = '';
346
+ const {
347
+ implementation,
348
+ createNodeIterator,
349
+ createDocumentFragment,
350
+ getElementsByTagName
351
+ } = document;
352
+ const {
353
+ importNode
354
+ } = originalDocument;
355
+ let hooks = _createHooksMap();
356
+ /**
357
+ * Expose whether this browser supports running the full DOMPurify.
358
+ */
359
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
360
+ const {
361
+ MUSTACHE_EXPR,
362
+ ERB_EXPR,
363
+ TMPLIT_EXPR,
364
+ DATA_ATTR,
365
+ ARIA_ATTR,
366
+ IS_SCRIPT_OR_DATA,
367
+ ATTR_WHITESPACE,
368
+ CUSTOM_ELEMENT
369
+ } = EXPRESSIONS;
370
+ let {
371
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
372
+ } = EXPRESSIONS;
373
+ /**
374
+ * We consider the elements and attributes below to be safe. Ideally
375
+ * don't add any new ones but feel free to remove unwanted ones.
376
+ */
377
+ /* allowed element names */
378
+ let ALLOWED_TAGS = null;
379
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
380
+ /* Allowed attribute names */
381
+ let ALLOWED_ATTR = null;
382
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
383
+ /*
384
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
385
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
386
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
387
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
388
+ */
389
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
390
+ tagNameCheck: {
391
+ writable: true,
392
+ configurable: false,
393
+ enumerable: true,
394
+ value: null
395
+ },
396
+ attributeNameCheck: {
397
+ writable: true,
398
+ configurable: false,
399
+ enumerable: true,
400
+ value: null
401
+ },
402
+ allowCustomizedBuiltInElements: {
403
+ writable: true,
404
+ configurable: false,
405
+ enumerable: true,
406
+ value: false
407
+ }
408
+ }));
409
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
410
+ let FORBID_TAGS = null;
411
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
412
+ let FORBID_ATTR = null;
413
+ /* Decide if ARIA attributes are okay */
414
+ let ALLOW_ARIA_ATTR = true;
415
+ /* Decide if custom data attributes are okay */
416
+ let ALLOW_DATA_ATTR = true;
417
+ /* Decide if unknown protocols are okay */
418
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
419
+ /* Decide if self-closing tags in attributes are allowed.
420
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
421
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
422
+ /* Output should be safe for common template engines.
423
+ * This means, DOMPurify removes data attributes, mustaches and ERB
424
+ */
425
+ let SAFE_FOR_TEMPLATES = false;
426
+ /* Output should be safe even for XML used within HTML and alike.
427
+ * This means, DOMPurify removes comments when containing risky content.
428
+ */
429
+ let SAFE_FOR_XML = true;
430
+ /* Decide if document with <html>... should be returned */
431
+ let WHOLE_DOCUMENT = false;
432
+ /* Track whether config is already set on this instance of DOMPurify. */
433
+ let SET_CONFIG = false;
434
+ /* Decide if all elements (e.g. style, script) must be children of
435
+ * document.body. By default, browsers might move them to document.head */
436
+ let FORCE_BODY = false;
437
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
438
+ * string (or a TrustedHTML object if Trusted Types are supported).
439
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
440
+ */
441
+ let RETURN_DOM = false;
442
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
443
+ * string (or a TrustedHTML object if Trusted Types are supported) */
444
+ let RETURN_DOM_FRAGMENT = false;
445
+ /* Try to return a Trusted Type object instead of a string, return a string in
446
+ * case Trusted Types are not supported */
447
+ let RETURN_TRUSTED_TYPE = false;
448
+ /* Output should be free from DOM clobbering attacks?
449
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
450
+ */
451
+ let SANITIZE_DOM = true;
452
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
453
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
454
+ *
455
+ * HTML/DOM spec rules that enable DOM Clobbering:
456
+ * - Named Access on Window (§7.3.3)
457
+ * - DOM Tree Accessors (§3.1.5)
458
+ * - Form Element Parent-Child Relations (§4.10.3)
459
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
460
+ * - HTMLCollection (§4.2.10.2)
461
+ *
462
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
463
+ * with a constant string, i.e., `user-content-`
464
+ */
465
+ let SANITIZE_NAMED_PROPS = false;
466
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
467
+ /* Keep element content when removing element? */
468
+ let KEEP_CONTENT = true;
469
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
470
+ * of importing it into a new Document and returning a sanitized copy */
471
+ let IN_PLACE = false;
472
+ /* Allow usage of profiles like html, svg and mathMl */
473
+ let USE_PROFILES = {};
474
+ /* Tags to ignore content of when KEEP_CONTENT is true */
475
+ let FORBID_CONTENTS = null;
476
+ 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']);
477
+ /* Tags that are safe for data: URIs */
478
+ let DATA_URI_TAGS = null;
479
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
480
+ /* Attributes safe for values like "javascript:" */
481
+ let URI_SAFE_ATTRIBUTES = null;
482
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
483
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
484
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
485
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
486
+ /* Document namespace */
487
+ let NAMESPACE = HTML_NAMESPACE;
488
+ let IS_EMPTY_INPUT = false;
489
+ /* Allowed XHTML+XML namespaces */
490
+ let ALLOWED_NAMESPACES = null;
491
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
492
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
493
+ let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
494
+ // Certain elements are allowed in both SVG and HTML
495
+ // namespace. We need to specify them explicitly
496
+ // so that they don't get erroneously deleted from
497
+ // HTML namespace.
498
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
499
+ /* Parsing of strict XHTML documents */
500
+ let PARSER_MEDIA_TYPE = null;
501
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
502
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
503
+ let transformCaseFunc = null;
504
+ /* Keep a reference to config to pass to hooks */
505
+ let CONFIG = null;
506
+ /* Ideally, do not touch anything below this line */
507
+ /* ______________________________________________ */
508
+ const formElement = document.createElement('form');
509
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
510
+ return testValue instanceof RegExp || testValue instanceof Function;
511
+ };
512
+ /**
513
+ * _parseConfig
514
+ *
515
+ * @param cfg optional config literal
516
+ */
517
+ // eslint-disable-next-line complexity
518
+ const _parseConfig = function _parseConfig() {
519
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
520
+ if (CONFIG && CONFIG === cfg) {
521
+ return;
522
+ }
523
+ /* Shield configuration object from tampering */
524
+ if (!cfg || typeof cfg !== 'object') {
525
+ cfg = {};
526
+ }
527
+ /* Shield configuration object from prototype pollution */
528
+ cfg = clone(cfg);
529
+ PARSER_MEDIA_TYPE =
530
+ // eslint-disable-next-line unicorn/prefer-includes
531
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
532
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
533
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
534
+ /* Set configuration parameters */
535
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
536
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
537
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
538
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
539
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
540
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
541
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
542
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
543
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
544
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
545
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
546
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
547
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
548
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
549
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
550
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
551
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
552
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
553
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
554
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
555
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
556
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
557
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
558
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
559
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
560
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
561
+ MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
562
+ HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
563
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
564
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
565
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
566
+ }
567
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
568
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
569
+ }
570
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
571
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
572
+ }
573
+ if (SAFE_FOR_TEMPLATES) {
574
+ ALLOW_DATA_ATTR = false;
575
+ }
576
+ if (RETURN_DOM_FRAGMENT) {
577
+ RETURN_DOM = true;
578
+ }
579
+ /* Parse profile info */
580
+ if (USE_PROFILES) {
581
+ ALLOWED_TAGS = addToSet({}, text);
582
+ ALLOWED_ATTR = [];
583
+ if (USE_PROFILES.html === true) {
584
+ addToSet(ALLOWED_TAGS, html$1);
585
+ addToSet(ALLOWED_ATTR, html);
586
+ }
587
+ if (USE_PROFILES.svg === true) {
588
+ addToSet(ALLOWED_TAGS, svg$1);
589
+ addToSet(ALLOWED_ATTR, svg);
590
+ addToSet(ALLOWED_ATTR, xml);
591
+ }
592
+ if (USE_PROFILES.svgFilters === true) {
593
+ addToSet(ALLOWED_TAGS, svgFilters);
594
+ addToSet(ALLOWED_ATTR, svg);
595
+ addToSet(ALLOWED_ATTR, xml);
596
+ }
597
+ if (USE_PROFILES.mathMl === true) {
598
+ addToSet(ALLOWED_TAGS, mathMl$1);
599
+ addToSet(ALLOWED_ATTR, mathMl);
600
+ addToSet(ALLOWED_ATTR, xml);
601
+ }
602
+ }
603
+ /* Merge configuration parameters */
604
+ if (cfg.ADD_TAGS) {
605
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
606
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
607
+ }
608
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
609
+ }
610
+ if (cfg.ADD_ATTR) {
611
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
612
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
613
+ }
614
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
615
+ }
616
+ if (cfg.ADD_URI_SAFE_ATTR) {
617
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
618
+ }
619
+ if (cfg.FORBID_CONTENTS) {
620
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
621
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
622
+ }
623
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
624
+ }
625
+ /* Add #text in case KEEP_CONTENT is set to true */
626
+ if (KEEP_CONTENT) {
627
+ ALLOWED_TAGS['#text'] = true;
628
+ }
629
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
630
+ if (WHOLE_DOCUMENT) {
631
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
632
+ }
633
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
634
+ if (ALLOWED_TAGS.table) {
635
+ addToSet(ALLOWED_TAGS, ['tbody']);
636
+ delete FORBID_TAGS.tbody;
637
+ }
638
+ if (cfg.TRUSTED_TYPES_POLICY) {
639
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
640
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
641
+ }
642
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
643
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
644
+ }
645
+ // Overwrite existing TrustedTypes policy.
646
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
647
+ // Sign local variables required by `sanitize`.
648
+ emptyHTML = trustedTypesPolicy.createHTML('');
649
+ } else {
650
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
651
+ if (trustedTypesPolicy === undefined) {
652
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
653
+ }
654
+ // If creating the internal policy succeeded sign internal variables.
655
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
656
+ emptyHTML = trustedTypesPolicy.createHTML('');
657
+ }
658
+ }
659
+ // Prevent further manipulation of configuration.
660
+ // Not available in IE8, Safari 5, etc.
661
+ if (freeze) {
662
+ freeze(cfg);
663
+ }
664
+ CONFIG = cfg;
665
+ };
666
+ /* Keep track of all possible SVG and MathML tags
667
+ * so that we can perform the namespace checks
668
+ * correctly. */
669
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
670
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
671
+ /**
672
+ * @param element a DOM element whose namespace is being checked
673
+ * @returns Return false if the element has a
674
+ * namespace that a spec-compliant parser would never
675
+ * return. Return true otherwise.
676
+ */
677
+ const _checkValidNamespace = function _checkValidNamespace(element) {
678
+ let parent = getParentNode(element);
679
+ // In JSDOM, if we're inside shadow DOM, then parentNode
680
+ // can be null. We just simulate parent in this case.
681
+ if (!parent || !parent.tagName) {
682
+ parent = {
683
+ namespaceURI: NAMESPACE,
684
+ tagName: 'template'
685
+ };
686
+ }
687
+ const tagName = stringToLowerCase(element.tagName);
688
+ const parentTagName = stringToLowerCase(parent.tagName);
689
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
690
+ return false;
691
+ }
692
+ if (element.namespaceURI === SVG_NAMESPACE) {
693
+ // The only way to switch from HTML namespace to SVG
694
+ // is via <svg>. If it happens via any other tag, then
695
+ // it should be killed.
696
+ if (parent.namespaceURI === HTML_NAMESPACE) {
697
+ return tagName === 'svg';
698
+ }
699
+ // The only way to switch from MathML to SVG is via`
700
+ // svg if parent is either <annotation-xml> or MathML
701
+ // text integration points.
702
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
703
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
704
+ }
705
+ // We only allow elements that are defined in SVG
706
+ // spec. All others are disallowed in SVG namespace.
707
+ return Boolean(ALL_SVG_TAGS[tagName]);
708
+ }
709
+ if (element.namespaceURI === MATHML_NAMESPACE) {
710
+ // The only way to switch from HTML namespace to MathML
711
+ // is via <math>. If it happens via any other tag, then
712
+ // it should be killed.
713
+ if (parent.namespaceURI === HTML_NAMESPACE) {
714
+ return tagName === 'math';
715
+ }
716
+ // The only way to switch from SVG to MathML is via
717
+ // <math> and HTML integration points
718
+ if (parent.namespaceURI === SVG_NAMESPACE) {
719
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
720
+ }
721
+ // We only allow elements that are defined in MathML
722
+ // spec. All others are disallowed in MathML namespace.
723
+ return Boolean(ALL_MATHML_TAGS[tagName]);
724
+ }
725
+ if (element.namespaceURI === HTML_NAMESPACE) {
726
+ // The only way to switch from SVG to HTML is via
727
+ // HTML integration points, and from MathML to HTML
728
+ // is via MathML text integration points
729
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
730
+ return false;
731
+ }
732
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
733
+ return false;
734
+ }
735
+ // We disallow tags that are specific for MathML
736
+ // or SVG and should never appear in HTML namespace
737
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
738
+ }
739
+ // For XHTML and XML documents that support custom namespaces
740
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
741
+ return true;
742
+ }
743
+ // The code should never reach this place (this means
744
+ // that the element somehow got namespace that is not
745
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
746
+ // Return false just in case.
747
+ return false;
748
+ };
749
+ /**
750
+ * _forceRemove
751
+ *
752
+ * @param node a DOM node
753
+ */
754
+ const _forceRemove = function _forceRemove(node) {
755
+ arrayPush(DOMPurify.removed, {
756
+ element: node
757
+ });
758
+ try {
759
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
760
+ getParentNode(node).removeChild(node);
761
+ } catch (_) {
762
+ remove(node);
763
+ }
764
+ };
765
+ /**
766
+ * _removeAttribute
767
+ *
768
+ * @param name an Attribute name
769
+ * @param element a DOM node
770
+ */
771
+ const _removeAttribute = function _removeAttribute(name, element) {
772
+ try {
773
+ arrayPush(DOMPurify.removed, {
774
+ attribute: element.getAttributeNode(name),
775
+ from: element
776
+ });
777
+ } catch (_) {
778
+ arrayPush(DOMPurify.removed, {
779
+ attribute: null,
780
+ from: element
781
+ });
782
+ }
783
+ element.removeAttribute(name);
784
+ // We void attribute values for unremovable "is" attributes
785
+ if (name === 'is') {
786
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
787
+ try {
788
+ _forceRemove(element);
789
+ } catch (_) {}
790
+ } else {
791
+ try {
792
+ element.setAttribute(name, '');
793
+ } catch (_) {}
794
+ }
795
+ }
796
+ };
797
+ /**
798
+ * _initDocument
799
+ *
800
+ * @param dirty - a string of dirty markup
801
+ * @return a DOM, filled with the dirty markup
802
+ */
803
+ const _initDocument = function _initDocument(dirty) {
804
+ /* Create a HTML document */
805
+ let doc = null;
806
+ let leadingWhitespace = null;
807
+ if (FORCE_BODY) {
808
+ dirty = '<remove></remove>' + dirty;
809
+ } else {
810
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
811
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
812
+ leadingWhitespace = matches && matches[0];
813
+ }
814
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
815
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
816
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
817
+ }
818
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
819
+ /*
820
+ * Use the DOMParser API by default, fallback later if needs be
821
+ * DOMParser not work for svg when has multiple root element.
822
+ */
823
+ if (NAMESPACE === HTML_NAMESPACE) {
824
+ try {
825
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
826
+ } catch (_) {}
827
+ }
828
+ /* Use createHTMLDocument in case DOMParser is not available */
829
+ if (!doc || !doc.documentElement) {
830
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
831
+ try {
832
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
833
+ } catch (_) {
834
+ // Syntax error if dirtyPayload is invalid xml
835
+ }
836
+ }
837
+ const body = doc.body || doc.documentElement;
838
+ if (dirty && leadingWhitespace) {
839
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
840
+ }
841
+ /* Work on whole document or just its body */
842
+ if (NAMESPACE === HTML_NAMESPACE) {
843
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
844
+ }
845
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
846
+ };
847
+ /**
848
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
849
+ *
850
+ * @param root The root element or node to start traversing on.
851
+ * @return The created NodeIterator
852
+ */
853
+ const _createNodeIterator = function _createNodeIterator(root) {
854
+ return createNodeIterator.call(root.ownerDocument || root, root,
855
+ // eslint-disable-next-line no-bitwise
856
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
857
+ };
858
+ /**
859
+ * _isClobbered
860
+ *
861
+ * @param element element to check for clobbering attacks
862
+ * @return true if clobbered, false if safe
863
+ */
864
+ const _isClobbered = function _isClobbered(element) {
865
+ return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
866
+ };
867
+ /**
868
+ * Checks whether the given object is a DOM node.
869
+ *
870
+ * @param value object to check whether it's a DOM node
871
+ * @return true is object is a DOM node
872
+ */
873
+ const _isNode = function _isNode(value) {
874
+ return typeof Node === 'function' && value instanceof Node;
875
+ };
876
+ function _executeHooks(hooks, currentNode, data) {
877
+ arrayForEach(hooks, hook => {
878
+ hook.call(DOMPurify, currentNode, data, CONFIG);
879
+ });
880
+ }
881
+ /**
882
+ * _sanitizeElements
883
+ *
884
+ * @protect nodeName
885
+ * @protect textContent
886
+ * @protect removeChild
887
+ * @param currentNode to check for permission to exist
888
+ * @return true if node was killed, false if left alive
889
+ */
890
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
891
+ let content = null;
892
+ /* Execute a hook if present */
893
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
894
+ /* Check if element is clobbered or can clobber */
895
+ if (_isClobbered(currentNode)) {
896
+ _forceRemove(currentNode);
897
+ return true;
898
+ }
899
+ /* Now let's check the element's type and name */
900
+ const tagName = transformCaseFunc(currentNode.nodeName);
901
+ /* Execute a hook if present */
902
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
903
+ tagName,
904
+ allowedTags: ALLOWED_TAGS
905
+ });
906
+ /* Detect mXSS attempts abusing namespace confusion */
907
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
908
+ _forceRemove(currentNode);
909
+ return true;
910
+ }
911
+ /* Remove any occurrence of processing instructions */
912
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
913
+ _forceRemove(currentNode);
914
+ return true;
915
+ }
916
+ /* Remove any kind of possibly harmful comments */
917
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
918
+ _forceRemove(currentNode);
919
+ return true;
920
+ }
921
+ /* Remove element if anything forbids its presence */
922
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
923
+ /* Check if we have a custom element to handle */
924
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
925
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
926
+ return false;
927
+ }
928
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
929
+ return false;
930
+ }
931
+ }
932
+ /* Keep content except for bad-listed elements */
933
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
934
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
935
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
936
+ if (childNodes && parentNode) {
937
+ const childCount = childNodes.length;
938
+ for (let i = childCount - 1; i >= 0; --i) {
939
+ const childClone = cloneNode(childNodes[i], true);
940
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
941
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
942
+ }
943
+ }
944
+ }
945
+ _forceRemove(currentNode);
946
+ return true;
947
+ }
948
+ /* Check whether element has a valid namespace */
949
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
950
+ _forceRemove(currentNode);
951
+ return true;
952
+ }
953
+ /* Make sure that older browsers don't get fallback-tag mXSS */
954
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
955
+ _forceRemove(currentNode);
956
+ return true;
957
+ }
958
+ /* Sanitize element content to be template-safe */
959
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
960
+ /* Get the element's text content */
961
+ content = currentNode.textContent;
962
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
963
+ content = stringReplace(content, expr, ' ');
964
+ });
965
+ if (currentNode.textContent !== content) {
966
+ arrayPush(DOMPurify.removed, {
967
+ element: currentNode.cloneNode()
831
968
  });
832
- // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
833
- const NODE_TYPE = {
834
- element: 1,
835
- attribute: 2,
836
- text: 3,
837
- cdataSection: 4,
838
- entityReference: 5,
839
- // Deprecated
840
- entityNode: 6,
841
- // Deprecated
842
- progressingInstruction: 7,
843
- comment: 8,
844
- document: 9,
845
- documentType: 10,
846
- documentFragment: 11,
847
- notation: 12 // Deprecated
848
- };
849
- const getGlobal = function getGlobal() {
850
- return typeof window === 'undefined' ? null : window;
851
- };
852
- /**
853
- * Creates a no-op policy for internal use only.
854
- * Don't export this function outside this module!
855
- * @param {TrustedTypePolicyFactory} trustedTypes The policy factory.
856
- * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
857
- * @return {TrustedTypePolicy} The policy created (or null, if Trusted Types
858
- * are not supported or creating the policy failed).
859
- */ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
860
- if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
861
- return null;
862
- }
863
- // Allow the callers to control the unique policy name
864
- // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
865
- // Policy creation with duplicate names throws in Trusted Types.
866
- let suffix = null;
867
- const ATTR_NAME = 'data-tt-policy-suffix';
868
- if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
869
- suffix = purifyHostElement.getAttribute(ATTR_NAME);
870
- }
871
- const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
872
- try {
873
- return trustedTypes.createPolicy(policyName, {
874
- createHTML (html) {
875
- return html;
876
- },
877
- createScriptURL (scriptUrl) {
878
- return scriptUrl;
879
- }
880
- });
881
- } catch (_) {
882
- // Policy creation failed (most likely another DOMPurify script has
883
- // already run). Skip creating the policy, as this will only cause errors
884
- // if TT are enforced.
885
- console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
886
- return null;
887
- }
888
- };
889
- function createDOMPurify() {
890
- let window1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
891
- const DOMPurify = (root)=>createDOMPurify(root);
892
- /**
893
- * Version label, exposed for easier checks
894
- * if DOMPurify is up to date or not
895
- */ DOMPurify.version = '3.1.7';
896
- /**
897
- * Array of elements that DOMPurify removed during sanitation.
898
- * Empty if nothing was removed.
899
- */ DOMPurify.removed = [];
900
- if (!window1 || !window1.document || window1.document.nodeType !== NODE_TYPE.document) {
901
- // Not running in a browser, provide a factory function
902
- // so that you can pass your own Window
903
- DOMPurify.isSupported = false;
904
- return DOMPurify;
905
- }
906
- let { document } = window1;
907
- const originalDocument = document;
908
- const currentScript = originalDocument.currentScript;
909
- const { DocumentFragment, HTMLTemplateElement, Node, Element, NodeFilter, NamedNodeMap = window1.NamedNodeMap || window1.MozNamedAttrMap, HTMLFormElement, DOMParser, trustedTypes } = window1;
910
- const ElementPrototype = Element.prototype;
911
- const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
912
- const remove = lookupGetter(ElementPrototype, 'remove');
913
- const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
914
- const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
915
- const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
916
- // As per issue #47, the web-components registry is inherited by a
917
- // new document created via createHTMLDocument. As per the spec
918
- // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
919
- // a new empty registry is used when creating a template contents owner
920
- // document, so we use that as our parent document to ensure nothing
921
- // is inherited.
922
- if (typeof HTMLTemplateElement === 'function') {
923
- const template = document.createElement('template');
924
- if (template.content && template.content.ownerDocument) {
925
- document = template.content.ownerDocument;
926
- }
927
- }
928
- let trustedTypesPolicy;
929
- let emptyHTML = '';
930
- const { implementation, createNodeIterator, createDocumentFragment, getElementsByTagName } = document;
931
- const { importNode } = originalDocument;
932
- let hooks = {};
933
- /**
934
- * Expose whether this browser supports running the full DOMPurify.
935
- */ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
936
- const { MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR, DATA_ATTR, ARIA_ATTR, IS_SCRIPT_OR_DATA, ATTR_WHITESPACE, CUSTOM_ELEMENT } = EXPRESSIONS;
937
- let { IS_ALLOWED_URI: IS_ALLOWED_URI$1 } = EXPRESSIONS;
938
- /**
939
- * We consider the elements and attributes below to be safe. Ideally
940
- * don't add any new ones but feel free to remove unwanted ones.
941
- */ /* allowed element names */ let ALLOWED_TAGS = null;
942
- const DEFAULT_ALLOWED_TAGS = addToSet({}, [
943
- ...html$1,
944
- ...svg$1,
945
- ...svgFilters,
946
- ...mathMl$1,
947
- ...text
948
- ]);
949
- /* Allowed attribute names */ let ALLOWED_ATTR = null;
950
- const DEFAULT_ALLOWED_ATTR = addToSet({}, [
951
- ...html,
952
- ...svg,
953
- ...mathMl,
954
- ...xml
955
- ]);
956
- /*
957
- * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
958
- * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
959
- * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
960
- * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
961
- */ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
962
- tagNameCheck: {
963
- writable: true,
964
- configurable: false,
965
- enumerable: true,
966
- value: null
967
- },
968
- attributeNameCheck: {
969
- writable: true,
970
- configurable: false,
971
- enumerable: true,
972
- value: null
973
- },
974
- allowCustomizedBuiltInElements: {
975
- writable: true,
976
- configurable: false,
977
- enumerable: true,
978
- value: false
979
- }
980
- }));
981
- /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */ let FORBID_TAGS = null;
982
- /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */ let FORBID_ATTR = null;
983
- /* Decide if ARIA attributes are okay */ let ALLOW_ARIA_ATTR = true;
984
- /* Decide if custom data attributes are okay */ let ALLOW_DATA_ATTR = true;
985
- /* Decide if unknown protocols are okay */ let ALLOW_UNKNOWN_PROTOCOLS = false;
986
- /* Decide if self-closing tags in attributes are allowed.
987
- * Usually removed due to a mXSS issue in jQuery 3.0 */ let ALLOW_SELF_CLOSE_IN_ATTR = true;
988
- /* Output should be safe for common template engines.
989
- * This means, DOMPurify removes data attributes, mustaches and ERB
990
- */ let SAFE_FOR_TEMPLATES = false;
991
- /* Output should be safe even for XML used within HTML and alike.
992
- * This means, DOMPurify removes comments when containing risky content.
993
- */ let SAFE_FOR_XML = true;
994
- /* Decide if document with <html>... should be returned */ let WHOLE_DOCUMENT = false;
995
- /* Track whether config is already set on this instance of DOMPurify. */ let SET_CONFIG = false;
996
- /* Decide if all elements (e.g. style, script) must be children of
997
- * document.body. By default, browsers might move them to document.head */ let FORCE_BODY = false;
998
- /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
999
- * string (or a TrustedHTML object if Trusted Types are supported).
1000
- * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
1001
- */ let RETURN_DOM = false;
1002
- /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
1003
- * string (or a TrustedHTML object if Trusted Types are supported) */ let RETURN_DOM_FRAGMENT = false;
1004
- /* Try to return a Trusted Type object instead of a string, return a string in
1005
- * case Trusted Types are not supported */ let RETURN_TRUSTED_TYPE = false;
1006
- /* Output should be free from DOM clobbering attacks?
1007
- * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
1008
- */ let SANITIZE_DOM = true;
1009
- /* Achieve full DOM Clobbering protection by isolating the namespace of named
1010
- * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
1011
- *
1012
- * HTML/DOM spec rules that enable DOM Clobbering:
1013
- * - Named Access on Window (§7.3.3)
1014
- * - DOM Tree Accessors (§3.1.5)
1015
- * - Form Element Parent-Child Relations (§4.10.3)
1016
- * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
1017
- * - HTMLCollection (§4.2.10.2)
1018
- *
1019
- * Namespace isolation is implemented by prefixing `id` and `name` attributes
1020
- * with a constant string, i.e., `user-content-`
1021
- */ let SANITIZE_NAMED_PROPS = false;
1022
- const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
1023
- /* Keep element content when removing element? */ let KEEP_CONTENT = true;
1024
- /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
1025
- * of importing it into a new Document and returning a sanitized copy */ let IN_PLACE = false;
1026
- /* Allow usage of profiles like html, svg and mathMl */ let USE_PROFILES = {};
1027
- /* Tags to ignore content of when KEEP_CONTENT is true */ let FORBID_CONTENTS = null;
1028
- const DEFAULT_FORBID_CONTENTS = addToSet({}, [
1029
- 'annotation-xml',
1030
- 'audio',
1031
- 'colgroup',
1032
- 'desc',
1033
- 'foreignobject',
1034
- 'head',
1035
- 'iframe',
1036
- 'math',
1037
- 'mi',
1038
- 'mn',
1039
- 'mo',
1040
- 'ms',
1041
- 'mtext',
1042
- 'noembed',
1043
- 'noframes',
1044
- 'noscript',
1045
- 'plaintext',
1046
- 'script',
1047
- 'style',
1048
- 'svg',
1049
- 'template',
1050
- 'thead',
1051
- 'title',
1052
- 'video',
1053
- 'xmp'
1054
- ]);
1055
- /* Tags that are safe for data: URIs */ let DATA_URI_TAGS = null;
1056
- const DEFAULT_DATA_URI_TAGS = addToSet({}, [
1057
- 'audio',
1058
- 'video',
1059
- 'img',
1060
- 'source',
1061
- 'image',
1062
- 'track'
1063
- ]);
1064
- /* Attributes safe for values like "javascript:" */ let URI_SAFE_ATTRIBUTES = null;
1065
- const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, [
1066
- 'alt',
1067
- 'class',
1068
- 'for',
1069
- 'id',
1070
- 'label',
1071
- 'name',
1072
- 'pattern',
1073
- 'placeholder',
1074
- 'role',
1075
- 'summary',
1076
- 'title',
1077
- 'value',
1078
- 'style',
1079
- 'xmlns'
1080
- ]);
1081
- const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
1082
- const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
1083
- const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
1084
- /* Document namespace */ let NAMESPACE = HTML_NAMESPACE;
1085
- let IS_EMPTY_INPUT = false;
1086
- /* Allowed XHTML+XML namespaces */ let ALLOWED_NAMESPACES = null;
1087
- const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [
1088
- MATHML_NAMESPACE,
1089
- SVG_NAMESPACE,
1090
- HTML_NAMESPACE
1091
- ], stringToString);
1092
- /* Parsing of strict XHTML documents */ let PARSER_MEDIA_TYPE = null;
1093
- const SUPPORTED_PARSER_MEDIA_TYPES = [
1094
- 'application/xhtml+xml',
1095
- 'text/html'
1096
- ];
1097
- const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
1098
- let transformCaseFunc = null;
1099
- /* Keep a reference to config to pass to hooks */ let CONFIG = null;
1100
- /* Ideally, do not touch anything below this line */ /* ______________________________________________ */ const formElement = document.createElement('form');
1101
- const isRegexOrFunction = function isRegexOrFunction(testValue) {
1102
- return testValue instanceof RegExp || testValue instanceof Function;
1103
- };
1104
- /**
1105
- * _parseConfig
1106
- *
1107
- * @param {Object} cfg optional config literal
1108
- */ // eslint-disable-next-line complexity
1109
- const _parseConfig = function _parseConfig() {
1110
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1111
- if (CONFIG && CONFIG === cfg) {
1112
- return;
1113
- }
1114
- /* Shield configuration object from tampering */ if (!cfg || typeof cfg !== 'object') {
1115
- cfg = {};
1116
- }
1117
- /* Shield configuration object from prototype pollution */ cfg = clone(cfg);
1118
- PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
1119
- SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
1120
- // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
1121
- transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
1122
- /* Set configuration parameters */ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
1123
- ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
1124
- ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
1125
- URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
1126
- cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
1127
- transformCaseFunc // eslint-disable-line indent
1128
- ) // eslint-disable-line indent
1129
- : DEFAULT_URI_SAFE_ATTRIBUTES;
1130
- DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
1131
- cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
1132
- transformCaseFunc // eslint-disable-line indent
1133
- ) // eslint-disable-line indent
1134
- : DEFAULT_DATA_URI_TAGS;
1135
- FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
1136
- FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
1137
- FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
1138
- USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
1139
- ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
1140
- ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
1141
- ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
1142
- ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
1143
- SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
1144
- SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
1145
- WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
1146
- RETURN_DOM = cfg.RETURN_DOM || false; // Default false
1147
- RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
1148
- RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
1149
- FORCE_BODY = cfg.FORCE_BODY || false; // Default false
1150
- SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
1151
- SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
1152
- KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
1153
- IN_PLACE = cfg.IN_PLACE || false; // Default false
1154
- IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
1155
- NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
1156
- CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
1157
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
1158
- CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
1159
- }
1160
- if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
1161
- CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
1162
- }
1163
- if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
1164
- CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
1165
- }
1166
- if (SAFE_FOR_TEMPLATES) {
1167
- ALLOW_DATA_ATTR = false;
1168
- }
1169
- if (RETURN_DOM_FRAGMENT) {
1170
- RETURN_DOM = true;
1171
- }
1172
- /* Parse profile info */ if (USE_PROFILES) {
1173
- ALLOWED_TAGS = addToSet({}, text);
1174
- ALLOWED_ATTR = [];
1175
- if (USE_PROFILES.html === true) {
1176
- addToSet(ALLOWED_TAGS, html$1);
1177
- addToSet(ALLOWED_ATTR, html);
1178
- }
1179
- if (USE_PROFILES.svg === true) {
1180
- addToSet(ALLOWED_TAGS, svg$1);
1181
- addToSet(ALLOWED_ATTR, svg);
1182
- addToSet(ALLOWED_ATTR, xml);
1183
- }
1184
- if (USE_PROFILES.svgFilters === true) {
1185
- addToSet(ALLOWED_TAGS, svgFilters);
1186
- addToSet(ALLOWED_ATTR, svg);
1187
- addToSet(ALLOWED_ATTR, xml);
1188
- }
1189
- if (USE_PROFILES.mathMl === true) {
1190
- addToSet(ALLOWED_TAGS, mathMl$1);
1191
- addToSet(ALLOWED_ATTR, mathMl);
1192
- addToSet(ALLOWED_ATTR, xml);
1193
- }
1194
- }
1195
- /* Merge configuration parameters */ if (cfg.ADD_TAGS) {
1196
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
1197
- ALLOWED_TAGS = clone(ALLOWED_TAGS);
1198
- }
1199
- addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1200
- }
1201
- if (cfg.ADD_ATTR) {
1202
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
1203
- ALLOWED_ATTR = clone(ALLOWED_ATTR);
1204
- }
1205
- addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1206
- }
1207
- if (cfg.ADD_URI_SAFE_ATTR) {
1208
- addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
1209
- }
1210
- if (cfg.FORBID_CONTENTS) {
1211
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
1212
- FORBID_CONTENTS = clone(FORBID_CONTENTS);
1213
- }
1214
- addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
1215
- }
1216
- /* Add #text in case KEEP_CONTENT is set to true */ if (KEEP_CONTENT) {
1217
- ALLOWED_TAGS['#text'] = true;
1218
- }
1219
- /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */ if (WHOLE_DOCUMENT) {
1220
- addToSet(ALLOWED_TAGS, [
1221
- 'html',
1222
- 'head',
1223
- 'body'
1224
- ]);
1225
- }
1226
- /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */ if (ALLOWED_TAGS.table) {
1227
- addToSet(ALLOWED_TAGS, [
1228
- 'tbody'
1229
- ]);
1230
- delete FORBID_TAGS.tbody;
1231
- }
1232
- if (cfg.TRUSTED_TYPES_POLICY) {
1233
- if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
1234
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
1235
- }
1236
- if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
1237
- throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
1238
- }
1239
- // Overwrite existing TrustedTypes policy.
1240
- trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
1241
- // Sign local variables required by `sanitize`.
1242
- emptyHTML = trustedTypesPolicy.createHTML('');
1243
- } else {
1244
- // Uninitialized policy, attempt to initialize the internal dompurify policy.
1245
- if (trustedTypesPolicy === undefined) {
1246
- trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
1247
- }
1248
- // If creating the internal policy succeeded sign internal variables.
1249
- if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
1250
- emptyHTML = trustedTypesPolicy.createHTML('');
1251
- }
1252
- }
1253
- // Prevent further manipulation of configuration.
1254
- // Not available in IE8, Safari 5, etc.
1255
- if (freeze) {
1256
- freeze(cfg);
1257
- }
1258
- CONFIG = cfg;
1259
- };
1260
- const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
1261
- 'mi',
1262
- 'mo',
1263
- 'mn',
1264
- 'ms',
1265
- 'mtext'
1266
- ]);
1267
- const HTML_INTEGRATION_POINTS = addToSet({}, [
1268
- 'annotation-xml'
1269
- ]);
1270
- // Certain elements are allowed in both SVG and HTML
1271
- // namespace. We need to specify them explicitly
1272
- // so that they don't get erroneously deleted from
1273
- // HTML namespace.
1274
- const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
1275
- 'title',
1276
- 'style',
1277
- 'font',
1278
- 'a',
1279
- 'script'
1280
- ]);
1281
- /* Keep track of all possible SVG and MathML tags
1282
- * so that we can perform the namespace checks
1283
- * correctly. */ const ALL_SVG_TAGS = addToSet({}, [
1284
- ...svg$1,
1285
- ...svgFilters,
1286
- ...svgDisallowed
1287
- ]);
1288
- const ALL_MATHML_TAGS = addToSet({}, [
1289
- ...mathMl$1,
1290
- ...mathMlDisallowed
1291
- ]);
1292
- /**
1293
- * @param {Element} element a DOM element whose namespace is being checked
1294
- * @returns {boolean} Return false if the element has a
1295
- * namespace that a spec-compliant parser would never
1296
- * return. Return true otherwise.
1297
- */ const _checkValidNamespace = function _checkValidNamespace(element) {
1298
- let parent = getParentNode(element);
1299
- // In JSDOM, if we're inside shadow DOM, then parentNode
1300
- // can be null. We just simulate parent in this case.
1301
- if (!parent || !parent.tagName) {
1302
- parent = {
1303
- namespaceURI: NAMESPACE,
1304
- tagName: 'template'
1305
- };
1306
- }
1307
- const tagName = stringToLowerCase(element.tagName);
1308
- const parentTagName = stringToLowerCase(parent.tagName);
1309
- if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1310
- return false;
1311
- }
1312
- if (element.namespaceURI === SVG_NAMESPACE) {
1313
- // The only way to switch from HTML namespace to SVG
1314
- // is via <svg>. If it happens via any other tag, then
1315
- // it should be killed.
1316
- if (parent.namespaceURI === HTML_NAMESPACE) {
1317
- return tagName === 'svg';
1318
- }
1319
- // The only way to switch from MathML to SVG is via`
1320
- // svg if parent is either <annotation-xml> or MathML
1321
- // text integration points.
1322
- if (parent.namespaceURI === MATHML_NAMESPACE) {
1323
- return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1324
- }
1325
- // We only allow elements that are defined in SVG
1326
- // spec. All others are disallowed in SVG namespace.
1327
- return Boolean(ALL_SVG_TAGS[tagName]);
1328
- }
1329
- if (element.namespaceURI === MATHML_NAMESPACE) {
1330
- // The only way to switch from HTML namespace to MathML
1331
- // is via <math>. If it happens via any other tag, then
1332
- // it should be killed.
1333
- if (parent.namespaceURI === HTML_NAMESPACE) {
1334
- return tagName === 'math';
1335
- }
1336
- // The only way to switch from SVG to MathML is via
1337
- // <math> and HTML integration points
1338
- if (parent.namespaceURI === SVG_NAMESPACE) {
1339
- return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1340
- }
1341
- // We only allow elements that are defined in MathML
1342
- // spec. All others are disallowed in MathML namespace.
1343
- return Boolean(ALL_MATHML_TAGS[tagName]);
1344
- }
1345
- if (element.namespaceURI === HTML_NAMESPACE) {
1346
- // The only way to switch from SVG to HTML is via
1347
- // HTML integration points, and from MathML to HTML
1348
- // is via MathML text integration points
1349
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1350
- return false;
1351
- }
1352
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1353
- return false;
1354
- }
1355
- // We disallow tags that are specific for MathML
1356
- // or SVG and should never appear in HTML namespace
1357
- return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1358
- }
1359
- // For XHTML and XML documents that support custom namespaces
1360
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1361
- return true;
1362
- }
1363
- // The code should never reach this place (this means
1364
- // that the element somehow got namespace that is not
1365
- // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1366
- // Return false just in case.
1367
- return false;
1368
- };
1369
- /**
1370
- * _forceRemove
1371
- *
1372
- * @param {Node} node a DOM node
1373
- */ const _forceRemove = function _forceRemove(node) {
1374
- arrayPush(DOMPurify.removed, {
1375
- element: node
1376
- });
1377
- try {
1378
- // eslint-disable-next-line unicorn/prefer-dom-node-remove
1379
- getParentNode(node).removeChild(node);
1380
- } catch (_) {
1381
- remove(node);
1382
- }
1383
- };
1384
- /**
1385
- * _removeAttribute
1386
- *
1387
- * @param {String} name an Attribute name
1388
- * @param {Node} node a DOM node
1389
- */ const _removeAttribute = function _removeAttribute(name, node) {
1390
- try {
1391
- arrayPush(DOMPurify.removed, {
1392
- attribute: node.getAttributeNode(name),
1393
- from: node
1394
- });
1395
- } catch (_) {
1396
- arrayPush(DOMPurify.removed, {
1397
- attribute: null,
1398
- from: node
1399
- });
1400
- }
1401
- node.removeAttribute(name);
1402
- // We void attribute values for unremovable "is"" attributes
1403
- if (name === 'is' && !ALLOWED_ATTR[name]) {
1404
- if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1405
- try {
1406
- _forceRemove(node);
1407
- } catch (_) {}
1408
- } else {
1409
- try {
1410
- node.setAttribute(name, '');
1411
- } catch (_) {}
1412
- }
1413
- }
1414
- };
1415
- /**
1416
- * _initDocument
1417
- *
1418
- * @param {String} dirty a string of dirty markup
1419
- * @return {Document} a DOM, filled with the dirty markup
1420
- */ const _initDocument = function _initDocument(dirty) {
1421
- /* Create a HTML document */ let doc = null;
1422
- let leadingWhitespace = null;
1423
- if (FORCE_BODY) {
1424
- dirty = '<remove></remove>' + dirty;
1425
- } else {
1426
- /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1427
- leadingWhitespace = matches && matches[0];
1428
- }
1429
- if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1430
- // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1431
- dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1432
- }
1433
- const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1434
- /*
1435
- * Use the DOMParser API by default, fallback later if needs be
1436
- * DOMParser not work for svg when has multiple root element.
1437
- */ if (NAMESPACE === HTML_NAMESPACE) {
1438
- try {
1439
- doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1440
- } catch (_) {}
1441
- }
1442
- /* Use createHTMLDocument in case DOMParser is not available */ if (!doc || !doc.documentElement) {
1443
- doc = implementation.createDocument(NAMESPACE, 'template', null);
1444
- try {
1445
- doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1446
- } catch (_) {
1447
- // Syntax error if dirtyPayload is invalid xml
1448
- }
1449
- }
1450
- const body = doc.body || doc.documentElement;
1451
- if (dirty && leadingWhitespace) {
1452
- body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1453
- }
1454
- /* Work on whole document or just its body */ if (NAMESPACE === HTML_NAMESPACE) {
1455
- return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1456
- }
1457
- return WHOLE_DOCUMENT ? doc.documentElement : body;
1458
- };
1459
- /**
1460
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1461
- *
1462
- * @param {Node} root The root element or node to start traversing on.
1463
- * @return {NodeIterator} The created NodeIterator
1464
- */ const _createNodeIterator = function _createNodeIterator(root) {
1465
- return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
1466
- NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1467
- };
1468
- /**
1469
- * _isClobbered
1470
- *
1471
- * @param {Node} elm element to check for clobbering attacks
1472
- * @return {Boolean} true if clobbered, false if safe
1473
- */ const _isClobbered = function _isClobbered(elm) {
1474
- 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');
1475
- };
1476
- /**
1477
- * Checks whether the given object is a DOM node.
1478
- *
1479
- * @param {Node} object object to check whether it's a DOM node
1480
- * @return {Boolean} true is object is a DOM node
1481
- */ const _isNode = function _isNode(object) {
1482
- return typeof Node === 'function' && object instanceof Node;
1483
- };
1484
- /**
1485
- * _executeHook
1486
- * Execute user configurable hooks
1487
- *
1488
- * @param {String} entryPoint Name of the hook's entry point
1489
- * @param {Node} currentNode node to work on with the hook
1490
- * @param {Object} data additional hook parameters
1491
- */ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
1492
- if (!hooks[entryPoint]) {
1493
- return;
1494
- }
1495
- arrayForEach(hooks[entryPoint], (hook)=>{
1496
- hook.call(DOMPurify, currentNode, data, CONFIG);
1497
- });
1498
- };
1499
- /**
1500
- * _sanitizeElements
1501
- *
1502
- * @protect nodeName
1503
- * @protect textContent
1504
- * @protect removeChild
1505
- *
1506
- * @param {Node} currentNode to check for permission to exist
1507
- * @return {Boolean} true if node was killed, false if left alive
1508
- */ const _sanitizeElements = function _sanitizeElements(currentNode) {
1509
- let content = null;
1510
- /* Execute a hook if present */ _executeHook('beforeSanitizeElements', currentNode, null);
1511
- /* Check if element is clobbered or can clobber */ if (_isClobbered(currentNode)) {
1512
- _forceRemove(currentNode);
1513
- return true;
1514
- }
1515
- /* Now let's check the element's type and name */ const tagName = transformCaseFunc(currentNode.nodeName);
1516
- /* Execute a hook if present */ _executeHook('uponSanitizeElement', currentNode, {
1517
- tagName,
1518
- allowedTags: ALLOWED_TAGS
1519
- });
1520
- /* Detect mXSS attempts abusing namespace confusion */ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1521
- _forceRemove(currentNode);
1522
- return true;
1523
- }
1524
- /* Remove any occurrence of processing instructions */ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
1525
- _forceRemove(currentNode);
1526
- return true;
1527
- }
1528
- /* Remove any kind of possibly harmful comments */ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
1529
- _forceRemove(currentNode);
1530
- return true;
1531
- }
1532
- /* Remove element if anything forbids its presence */ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1533
- /* Check if we have a custom element to handle */ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
1534
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1535
- return false;
1536
- }
1537
- if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
1538
- return false;
1539
- }
1540
- }
1541
- /* Keep content except for bad-listed elements */ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1542
- const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1543
- const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1544
- if (childNodes && parentNode) {
1545
- const childCount = childNodes.length;
1546
- for(let i = childCount - 1; i >= 0; --i){
1547
- const childClone = cloneNode(childNodes[i], true);
1548
- childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
1549
- parentNode.insertBefore(childClone, getNextSibling(currentNode));
1550
- }
1551
- }
1552
- }
1553
- _forceRemove(currentNode);
1554
- return true;
1555
- }
1556
- /* Check whether element has a valid namespace */ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1557
- _forceRemove(currentNode);
1558
- return true;
1559
- }
1560
- /* Make sure that older browsers don't get fallback-tag mXSS */ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1561
- _forceRemove(currentNode);
1562
- return true;
1563
- }
1564
- /* Sanitize element content to be template-safe */ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1565
- /* Get the element's text content */ content = currentNode.textContent;
1566
- arrayForEach([
1567
- MUSTACHE_EXPR,
1568
- ERB_EXPR,
1569
- TMPLIT_EXPR
1570
- ], (expr)=>{
1571
- content = stringReplace(content, expr, ' ');
1572
- });
1573
- if (currentNode.textContent !== content) {
1574
- arrayPush(DOMPurify.removed, {
1575
- element: currentNode.cloneNode()
1576
- });
1577
- currentNode.textContent = content;
1578
- }
1579
- }
1580
- /* Execute a hook if present */ _executeHook('afterSanitizeElements', currentNode, null);
1581
- return false;
1582
- };
1583
- /**
1584
- * _isValidAttribute
1585
- *
1586
- * @param {string} lcTag Lowercase tag name of containing element.
1587
- * @param {string} lcName Lowercase attribute name.
1588
- * @param {string} value Attribute value.
1589
- * @return {Boolean} Returns true if `value` is valid, otherwise false.
1590
- */ // eslint-disable-next-line complexity
1591
- const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1592
- /* Make sure attribute cannot clobber */ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1593
- return false;
1594
- }
1595
- /* Allow valid data-* attributes: At least one character after "-"
1596
- (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1597
- XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1598
- We don't need to check the value; it's always URI safe. */ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ;
1599
- else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ;
1600
- else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1601
- if (// First condition does a very basic check if a) it's basically a valid custom element tagname AND
1602
- // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1603
- // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1604
- _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
1605
- // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1606
- 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))) ;
1607
- else {
1608
- return false;
1609
- }
1610
- /* Check value is safe. First, is attr inert? If so, is safe */ } else if (URI_SAFE_ATTRIBUTES[lcName]) ;
1611
- else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ;
1612
- else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ;
1613
- else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ;
1614
- else if (value) {
1615
- return false;
1616
- } else ;
1617
- return true;
1618
- };
1619
- /**
1620
- * _isBasicCustomElement
1621
- * checks if at least one dash is included in tagName, and it's not the first char
1622
- * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1623
- *
1624
- * @param {string} tagName name of the tag of the node to sanitize
1625
- * @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1626
- */ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1627
- return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1628
- };
1629
- /**
1630
- * _sanitizeAttributes
1631
- *
1632
- * @protect attributes
1633
- * @protect nodeName
1634
- * @protect removeAttribute
1635
- * @protect setAttribute
1636
- *
1637
- * @param {Node} currentNode to sanitize
1638
- */ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1639
- /* Execute a hook if present */ _executeHook('beforeSanitizeAttributes', currentNode, null);
1640
- const { attributes } = currentNode;
1641
- /* Check if we have attributes; if not we might have a text node */ if (!attributes) {
1642
- return;
1643
- }
1644
- const hookEvent = {
1645
- attrName: '',
1646
- attrValue: '',
1647
- keepAttr: true,
1648
- allowedAttributes: ALLOWED_ATTR
1649
- };
1650
- let l = attributes.length;
1651
- /* Go backwards over all attributes; safely remove bad ones */ while(l--){
1652
- const attr = attributes[l];
1653
- const { name, namespaceURI, value: attrValue } = attr;
1654
- const lcName = transformCaseFunc(name);
1655
- let value = name === 'value' ? attrValue : stringTrim(attrValue);
1656
- /* Execute a hook if present */ hookEvent.attrName = lcName;
1657
- hookEvent.attrValue = value;
1658
- hookEvent.keepAttr = true;
1659
- hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1660
- _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1661
- value = hookEvent.attrValue;
1662
- /* Did the hooks approve of the attribute? */ if (hookEvent.forceKeepAttr) {
1663
- continue;
1664
- }
1665
- /* Remove attribute */ _removeAttribute(name, currentNode);
1666
- /* Did the hooks approve of the attribute? */ if (!hookEvent.keepAttr) {
1667
- continue;
1668
- }
1669
- /* Work around a security issue in jQuery 3.0 */ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1670
- _removeAttribute(name, currentNode);
1671
- continue;
1672
- }
1673
- /* Sanitize attribute content to be template-safe */ if (SAFE_FOR_TEMPLATES) {
1674
- arrayForEach([
1675
- MUSTACHE_EXPR,
1676
- ERB_EXPR,
1677
- TMPLIT_EXPR
1678
- ], (expr)=>{
1679
- value = stringReplace(value, expr, ' ');
1680
- });
1681
- }
1682
- /* Is `value` valid for this attribute? */ const lcTag = transformCaseFunc(currentNode.nodeName);
1683
- if (!_isValidAttribute(lcTag, lcName, value)) {
1684
- continue;
1685
- }
1686
- /* Full DOM Clobbering protection via namespace isolation,
1687
- * Prefix id and name attributes with `user-content-`
1688
- */ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1689
- // Remove the attribute with this value
1690
- _removeAttribute(name, currentNode);
1691
- // Prefix the value and later re-create the attribute with the sanitized value
1692
- value = SANITIZE_NAMED_PROPS_PREFIX + value;
1693
- }
1694
- /* Work around a security issue with comments inside attributes */ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
1695
- _removeAttribute(name, currentNode);
1696
- continue;
1697
- }
1698
- /* Handle attributes that require Trusted Types */ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1699
- if (namespaceURI) ;
1700
- else {
1701
- switch(trustedTypes.getAttributeType(lcTag, lcName)){
1702
- case 'TrustedHTML':
1703
- {
1704
- value = trustedTypesPolicy.createHTML(value);
1705
- break;
1706
- }
1707
- case 'TrustedScriptURL':
1708
- {
1709
- value = trustedTypesPolicy.createScriptURL(value);
1710
- break;
1711
- }
1712
- }
1713
- }
1714
- }
1715
- /* Handle invalid data-* attribute set by try-catching it */ try {
1716
- if (namespaceURI) {
1717
- currentNode.setAttributeNS(namespaceURI, name, value);
1718
- } else {
1719
- /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */ currentNode.setAttribute(name, value);
1720
- }
1721
- if (_isClobbered(currentNode)) {
1722
- _forceRemove(currentNode);
1723
- } else {
1724
- arrayPop(DOMPurify.removed);
1725
- }
1726
- } catch (_) {}
1727
- }
1728
- /* Execute a hook if present */ _executeHook('afterSanitizeAttributes', currentNode, null);
1729
- };
1730
- /**
1731
- * _sanitizeShadowDOM
1732
- *
1733
- * @param {DocumentFragment} fragment to iterate over recursively
1734
- */ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1735
- let shadowNode = null;
1736
- const shadowIterator = _createNodeIterator(fragment);
1737
- /* Execute a hook if present */ _executeHook('beforeSanitizeShadowDOM', fragment, null);
1738
- while(shadowNode = shadowIterator.nextNode()){
1739
- /* Execute a hook if present */ _executeHook('uponSanitizeShadowNode', shadowNode, null);
1740
- /* Sanitize tags and elements */ if (_sanitizeElements(shadowNode)) {
1741
- continue;
1742
- }
1743
- /* Deep shadow DOM detected */ if (shadowNode.content instanceof DocumentFragment) {
1744
- _sanitizeShadowDOM(shadowNode.content);
1745
- }
1746
- /* Check attributes, sanitize if necessary */ _sanitizeAttributes(shadowNode);
1747
- }
1748
- /* Execute a hook if present */ _executeHook('afterSanitizeShadowDOM', fragment, null);
1749
- };
1750
- /**
1751
- * Sanitize
1752
- * Public method providing core sanitation functionality
1753
- *
1754
- * @param {String|Node} dirty string or DOM node
1755
- * @param {Object} cfg object
1756
- */ // eslint-disable-next-line complexity
1757
- DOMPurify.sanitize = function(dirty) {
1758
- let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1759
- let body = null;
1760
- let importedNode = null;
1761
- let currentNode = null;
1762
- let returnNode = null;
1763
- /* Make sure we have a string to sanitize.
1764
- DO NOT return early, as this will return the wrong type if
1765
- the user has requested a DOM object rather than a string */ IS_EMPTY_INPUT = !dirty;
1766
- if (IS_EMPTY_INPUT) {
1767
- dirty = '<!-->';
1768
- }
1769
- /* Stringify, in case dirty is an object */ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1770
- if (typeof dirty.toString === 'function') {
1771
- dirty = dirty.toString();
1772
- if (typeof dirty !== 'string') {
1773
- throw typeErrorCreate('dirty is not a string, aborting');
1774
- }
1775
- } else {
1776
- throw typeErrorCreate('toString is not a function');
1777
- }
1778
- }
1779
- /* Return dirty HTML if DOMPurify cannot run */ if (!DOMPurify.isSupported) {
1780
- return dirty;
1781
- }
1782
- /* Assign config vars */ if (!SET_CONFIG) {
1783
- _parseConfig(cfg);
1784
- }
1785
- /* Clean up removed elements */ DOMPurify.removed = [];
1786
- /* Check if dirty is correctly typed for IN_PLACE */ if (typeof dirty === 'string') {
1787
- IN_PLACE = false;
1788
- }
1789
- if (IN_PLACE) {
1790
- /* Do some early pre-sanitization to avoid unsafe root nodes */ if (dirty.nodeName) {
1791
- const tagName = transformCaseFunc(dirty.nodeName);
1792
- if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1793
- throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1794
- }
1795
- }
1796
- } else if (dirty instanceof Node) {
1797
- /* If dirty is a DOM element, append to an empty document to avoid
1798
- elements being stripped by the parser */ body = _initDocument('<!---->');
1799
- importedNode = body.ownerDocument.importNode(dirty, true);
1800
- if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1801
- /* Node is already a body, use as is */ body = importedNode;
1802
- } else if (importedNode.nodeName === 'HTML') {
1803
- body = importedNode;
1804
- } else {
1805
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1806
- body.appendChild(importedNode);
1807
- }
1808
- } else {
1809
- /* Exit directly if we have nothing to do */ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1810
- dirty.indexOf('<') === -1) {
1811
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1812
- }
1813
- /* Initialize the document to work on */ body = _initDocument(dirty);
1814
- /* Check we have a DOM node from the data */ if (!body) {
1815
- return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1816
- }
1817
- }
1818
- /* Remove first element node (ours) if FORCE_BODY is set */ if (body && FORCE_BODY) {
1819
- _forceRemove(body.firstChild);
1820
- }
1821
- /* Get node iterator */ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1822
- /* Now start iterating over the created document */ while(currentNode = nodeIterator.nextNode()){
1823
- /* Sanitize tags and elements */ if (_sanitizeElements(currentNode)) {
1824
- continue;
1825
- }
1826
- /* Shadow DOM detected, sanitize it */ if (currentNode.content instanceof DocumentFragment) {
1827
- _sanitizeShadowDOM(currentNode.content);
1828
- }
1829
- /* Check attributes, sanitize if necessary */ _sanitizeAttributes(currentNode);
1830
- }
1831
- /* If we sanitized `dirty` in-place, return it. */ if (IN_PLACE) {
1832
- return dirty;
1833
- }
1834
- /* Return sanitized string or DOM */ if (RETURN_DOM) {
1835
- if (RETURN_DOM_FRAGMENT) {
1836
- returnNode = createDocumentFragment.call(body.ownerDocument);
1837
- while(body.firstChild){
1838
- // eslint-disable-next-line unicorn/prefer-dom-node-append
1839
- returnNode.appendChild(body.firstChild);
1840
- }
1841
- } else {
1842
- returnNode = body;
1843
- }
1844
- if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1845
- /*
1846
- AdoptNode() is not used because internal state is not reset
1847
- (e.g. the past names map of a HTMLFormElement), this is safe
1848
- in theory but we would rather not risk another attack vector.
1849
- The state that is cloned by importNode() is explicitly defined
1850
- by the specs.
1851
- */ returnNode = importNode.call(originalDocument, returnNode, true);
1852
- }
1853
- return returnNode;
1854
- }
1855
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1856
- /* Serialize doctype if allowed */ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1857
- serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1858
- }
1859
- /* Sanitize final string template-safe */ if (SAFE_FOR_TEMPLATES) {
1860
- arrayForEach([
1861
- MUSTACHE_EXPR,
1862
- ERB_EXPR,
1863
- TMPLIT_EXPR
1864
- ], (expr)=>{
1865
- serializedHTML = stringReplace(serializedHTML, expr, ' ');
1866
- });
1867
- }
1868
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1869
- };
1870
- /**
1871
- * Public method to set the configuration once
1872
- * setConfig
1873
- *
1874
- * @param {Object} cfg configuration object
1875
- */ DOMPurify.setConfig = function() {
1876
- let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1877
- _parseConfig(cfg);
1878
- SET_CONFIG = true;
1879
- };
1880
- /**
1881
- * Public method to remove the configuration
1882
- * clearConfig
1883
- *
1884
- */ DOMPurify.clearConfig = function() {
1885
- CONFIG = null;
1886
- SET_CONFIG = false;
1887
- };
1888
- /**
1889
- * Public method to check if an attribute value is valid.
1890
- * Uses last set config, if any. Otherwise, uses config defaults.
1891
- * isValidAttribute
1892
- *
1893
- * @param {String} tag Tag name of containing element.
1894
- * @param {String} attr Attribute name.
1895
- * @param {String} value Attribute value.
1896
- * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1897
- */ DOMPurify.isValidAttribute = function(tag, attr, value) {
1898
- /* Initialize shared config vars if necessary. */ if (!CONFIG) {
1899
- _parseConfig({});
1900
- }
1901
- const lcTag = transformCaseFunc(tag);
1902
- const lcName = transformCaseFunc(attr);
1903
- return _isValidAttribute(lcTag, lcName, value);
1904
- };
1905
- /**
1906
- * AddHook
1907
- * Public method to add DOMPurify hooks
1908
- *
1909
- * @param {String} entryPoint entry point for the hook to add
1910
- * @param {Function} hookFunction function to execute
1911
- */ DOMPurify.addHook = function(entryPoint, hookFunction) {
1912
- if (typeof hookFunction !== 'function') {
1913
- return;
1914
- }
1915
- hooks[entryPoint] = hooks[entryPoint] || [];
1916
- arrayPush(hooks[entryPoint], hookFunction);
1917
- };
1918
- /**
1919
- * RemoveHook
1920
- * Public method to remove a DOMPurify hook at a given entryPoint
1921
- * (pops it from the stack of hooks if more are present)
1922
- *
1923
- * @param {String} entryPoint entry point for the hook to remove
1924
- * @return {Function} removed(popped) hook
1925
- */ DOMPurify.removeHook = function(entryPoint) {
1926
- if (hooks[entryPoint]) {
1927
- return arrayPop(hooks[entryPoint]);
1928
- }
1929
- };
1930
- /**
1931
- * RemoveHooks
1932
- * Public method to remove all DOMPurify hooks at a given entryPoint
1933
- *
1934
- * @param {String} entryPoint entry point for the hooks to remove
1935
- */ DOMPurify.removeHooks = function(entryPoint) {
1936
- if (hooks[entryPoint]) {
1937
- hooks[entryPoint] = [];
1938
- }
1939
- };
1940
- /**
1941
- * RemoveAllHooks
1942
- * Public method to remove all DOMPurify hooks
1943
- */ DOMPurify.removeAllHooks = function() {
1944
- hooks = {};
1945
- };
1946
- return DOMPurify;
969
+ currentNode.textContent = content;
970
+ }
971
+ }
972
+ /* Execute a hook if present */
973
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
974
+ return false;
975
+ };
976
+ /**
977
+ * _isValidAttribute
978
+ *
979
+ * @param lcTag Lowercase tag name of containing element.
980
+ * @param lcName Lowercase attribute name.
981
+ * @param value Attribute value.
982
+ * @return Returns true if `value` is valid, otherwise false.
983
+ */
984
+ // eslint-disable-next-line complexity
985
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
986
+ /* Make sure attribute cannot clobber */
987
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
988
+ return false;
989
+ }
990
+ /* Allow valid data-* attributes: At least one character after "-"
991
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
992
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
993
+ We don't need to check the value; it's always URI safe. */
994
+ 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]) {
995
+ if (
996
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
997
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
998
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
999
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||
1000
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1001
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1002
+ 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 {
1003
+ return false;
1004
+ }
1005
+ /* Check value is safe. First, is attr inert? If so, is safe */
1006
+ } 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) {
1007
+ return false;
1008
+ } else ;
1009
+ return true;
1010
+ };
1011
+ /**
1012
+ * _isBasicCustomElement
1013
+ * checks if at least one dash is included in tagName, and it's not the first char
1014
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1015
+ *
1016
+ * @param tagName name of the tag of the node to sanitize
1017
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1018
+ */
1019
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1020
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1021
+ };
1022
+ /**
1023
+ * _sanitizeAttributes
1024
+ *
1025
+ * @protect attributes
1026
+ * @protect nodeName
1027
+ * @protect removeAttribute
1028
+ * @protect setAttribute
1029
+ *
1030
+ * @param currentNode to sanitize
1031
+ */
1032
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1033
+ /* Execute a hook if present */
1034
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1035
+ const {
1036
+ attributes
1037
+ } = currentNode;
1038
+ /* Check if we have attributes; if not we might have a text node */
1039
+ if (!attributes || _isClobbered(currentNode)) {
1040
+ return;
1041
+ }
1042
+ const hookEvent = {
1043
+ attrName: '',
1044
+ attrValue: '',
1045
+ keepAttr: true,
1046
+ allowedAttributes: ALLOWED_ATTR,
1047
+ forceKeepAttr: undefined
1048
+ };
1049
+ let l = attributes.length;
1050
+ /* Go backwards over all attributes; safely remove bad ones */
1051
+ while (l--) {
1052
+ const attr = attributes[l];
1053
+ const {
1054
+ name,
1055
+ namespaceURI,
1056
+ value: attrValue
1057
+ } = attr;
1058
+ const lcName = transformCaseFunc(name);
1059
+ let value = name === 'value' ? attrValue : stringTrim(attrValue);
1060
+ /* Execute a hook if present */
1061
+ hookEvent.attrName = lcName;
1062
+ hookEvent.attrValue = value;
1063
+ hookEvent.keepAttr = true;
1064
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1065
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1066
+ value = hookEvent.attrValue;
1067
+ /* Full DOM Clobbering protection via namespace isolation,
1068
+ * Prefix id and name attributes with `user-content-`
1069
+ */
1070
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1071
+ // Remove the attribute with this value
1072
+ _removeAttribute(name, currentNode);
1073
+ // Prefix the value and later re-create the attribute with the sanitized value
1074
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1075
+ }
1076
+ /* Work around a security issue with comments inside attributes */
1077
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
1078
+ _removeAttribute(name, currentNode);
1079
+ continue;
1080
+ }
1081
+ /* Did the hooks approve of the attribute? */
1082
+ if (hookEvent.forceKeepAttr) {
1083
+ continue;
1084
+ }
1085
+ /* Remove attribute */
1086
+ _removeAttribute(name, currentNode);
1087
+ /* Did the hooks approve of the attribute? */
1088
+ if (!hookEvent.keepAttr) {
1089
+ continue;
1090
+ }
1091
+ /* Work around a security issue in jQuery 3.0 */
1092
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1093
+ _removeAttribute(name, currentNode);
1094
+ continue;
1095
+ }
1096
+ /* Sanitize attribute content to be template-safe */
1097
+ if (SAFE_FOR_TEMPLATES) {
1098
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1099
+ value = stringReplace(value, expr, ' ');
1100
+ });
1101
+ }
1102
+ /* Is `value` valid for this attribute? */
1103
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1104
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1105
+ continue;
1106
+ }
1107
+ /* Handle attributes that require Trusted Types */
1108
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1109
+ if (namespaceURI) ; else {
1110
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1111
+ case 'TrustedHTML':
1112
+ {
1113
+ value = trustedTypesPolicy.createHTML(value);
1114
+ break;
1115
+ }
1116
+ case 'TrustedScriptURL':
1117
+ {
1118
+ value = trustedTypesPolicy.createScriptURL(value);
1119
+ break;
1120
+ }
1121
+ }
1122
+ }
1123
+ }
1124
+ /* Handle invalid data-* attribute set by try-catching it */
1125
+ try {
1126
+ if (namespaceURI) {
1127
+ currentNode.setAttributeNS(namespaceURI, name, value);
1128
+ } else {
1129
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1130
+ currentNode.setAttribute(name, value);
1947
1131
  }
1948
- var purify = createDOMPurify();
1949
- return purify;
1950
- });
1951
-
1952
- })(purify);
1953
- var purifyExports = purify.exports;
1132
+ if (_isClobbered(currentNode)) {
1133
+ _forceRemove(currentNode);
1134
+ } else {
1135
+ arrayPop(DOMPurify.removed);
1136
+ }
1137
+ } catch (_) {}
1138
+ }
1139
+ /* Execute a hook if present */
1140
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1141
+ };
1142
+ /**
1143
+ * _sanitizeShadowDOM
1144
+ *
1145
+ * @param fragment to iterate over recursively
1146
+ */
1147
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1148
+ let shadowNode = null;
1149
+ const shadowIterator = _createNodeIterator(fragment);
1150
+ /* Execute a hook if present */
1151
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1152
+ while (shadowNode = shadowIterator.nextNode()) {
1153
+ /* Execute a hook if present */
1154
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1155
+ /* Sanitize tags and elements */
1156
+ _sanitizeElements(shadowNode);
1157
+ /* Check attributes next */
1158
+ _sanitizeAttributes(shadowNode);
1159
+ /* Deep shadow DOM detected */
1160
+ if (shadowNode.content instanceof DocumentFragment) {
1161
+ _sanitizeShadowDOM(shadowNode.content);
1162
+ }
1163
+ }
1164
+ /* Execute a hook if present */
1165
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1166
+ };
1167
+ // eslint-disable-next-line complexity
1168
+ DOMPurify.sanitize = function (dirty) {
1169
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1170
+ let body = null;
1171
+ let importedNode = null;
1172
+ let currentNode = null;
1173
+ let returnNode = null;
1174
+ /* Make sure we have a string to sanitize.
1175
+ DO NOT return early, as this will return the wrong type if
1176
+ the user has requested a DOM object rather than a string */
1177
+ IS_EMPTY_INPUT = !dirty;
1178
+ if (IS_EMPTY_INPUT) {
1179
+ dirty = '<!-->';
1180
+ }
1181
+ /* Stringify, in case dirty is an object */
1182
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1183
+ if (typeof dirty.toString === 'function') {
1184
+ dirty = dirty.toString();
1185
+ if (typeof dirty !== 'string') {
1186
+ throw typeErrorCreate('dirty is not a string, aborting');
1187
+ }
1188
+ } else {
1189
+ throw typeErrorCreate('toString is not a function');
1190
+ }
1191
+ }
1192
+ /* Return dirty HTML if DOMPurify cannot run */
1193
+ if (!DOMPurify.isSupported) {
1194
+ return dirty;
1195
+ }
1196
+ /* Assign config vars */
1197
+ if (!SET_CONFIG) {
1198
+ _parseConfig(cfg);
1199
+ }
1200
+ /* Clean up removed elements */
1201
+ DOMPurify.removed = [];
1202
+ /* Check if dirty is correctly typed for IN_PLACE */
1203
+ if (typeof dirty === 'string') {
1204
+ IN_PLACE = false;
1205
+ }
1206
+ if (IN_PLACE) {
1207
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1208
+ if (dirty.nodeName) {
1209
+ const tagName = transformCaseFunc(dirty.nodeName);
1210
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1211
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1212
+ }
1213
+ }
1214
+ } else if (dirty instanceof Node) {
1215
+ /* If dirty is a DOM element, append to an empty document to avoid
1216
+ elements being stripped by the parser */
1217
+ body = _initDocument('<!---->');
1218
+ importedNode = body.ownerDocument.importNode(dirty, true);
1219
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1220
+ /* Node is already a body, use as is */
1221
+ body = importedNode;
1222
+ } else if (importedNode.nodeName === 'HTML') {
1223
+ body = importedNode;
1224
+ } else {
1225
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1226
+ body.appendChild(importedNode);
1227
+ }
1228
+ } else {
1229
+ /* Exit directly if we have nothing to do */
1230
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1231
+ // eslint-disable-next-line unicorn/prefer-includes
1232
+ dirty.indexOf('<') === -1) {
1233
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1234
+ }
1235
+ /* Initialize the document to work on */
1236
+ body = _initDocument(dirty);
1237
+ /* Check we have a DOM node from the data */
1238
+ if (!body) {
1239
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1240
+ }
1241
+ }
1242
+ /* Remove first element node (ours) if FORCE_BODY is set */
1243
+ if (body && FORCE_BODY) {
1244
+ _forceRemove(body.firstChild);
1245
+ }
1246
+ /* Get node iterator */
1247
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1248
+ /* Now start iterating over the created document */
1249
+ while (currentNode = nodeIterator.nextNode()) {
1250
+ /* Sanitize tags and elements */
1251
+ _sanitizeElements(currentNode);
1252
+ /* Check attributes next */
1253
+ _sanitizeAttributes(currentNode);
1254
+ /* Shadow DOM detected, sanitize it */
1255
+ if (currentNode.content instanceof DocumentFragment) {
1256
+ _sanitizeShadowDOM(currentNode.content);
1257
+ }
1258
+ }
1259
+ /* If we sanitized `dirty` in-place, return it. */
1260
+ if (IN_PLACE) {
1261
+ return dirty;
1262
+ }
1263
+ /* Return sanitized string or DOM */
1264
+ if (RETURN_DOM) {
1265
+ if (RETURN_DOM_FRAGMENT) {
1266
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1267
+ while (body.firstChild) {
1268
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1269
+ returnNode.appendChild(body.firstChild);
1270
+ }
1271
+ } else {
1272
+ returnNode = body;
1273
+ }
1274
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1275
+ /*
1276
+ AdoptNode() is not used because internal state is not reset
1277
+ (e.g. the past names map of a HTMLFormElement), this is safe
1278
+ in theory but we would rather not risk another attack vector.
1279
+ The state that is cloned by importNode() is explicitly defined
1280
+ by the specs.
1281
+ */
1282
+ returnNode = importNode.call(originalDocument, returnNode, true);
1283
+ }
1284
+ return returnNode;
1285
+ }
1286
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1287
+ /* Serialize doctype if allowed */
1288
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1289
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1290
+ }
1291
+ /* Sanitize final string template-safe */
1292
+ if (SAFE_FOR_TEMPLATES) {
1293
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1294
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
1295
+ });
1296
+ }
1297
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1298
+ };
1299
+ DOMPurify.setConfig = function () {
1300
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1301
+ _parseConfig(cfg);
1302
+ SET_CONFIG = true;
1303
+ };
1304
+ DOMPurify.clearConfig = function () {
1305
+ CONFIG = null;
1306
+ SET_CONFIG = false;
1307
+ };
1308
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1309
+ /* Initialize shared config vars if necessary. */
1310
+ if (!CONFIG) {
1311
+ _parseConfig({});
1312
+ }
1313
+ const lcTag = transformCaseFunc(tag);
1314
+ const lcName = transformCaseFunc(attr);
1315
+ return _isValidAttribute(lcTag, lcName, value);
1316
+ };
1317
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1318
+ if (typeof hookFunction !== 'function') {
1319
+ return;
1320
+ }
1321
+ arrayPush(hooks[entryPoint], hookFunction);
1322
+ };
1323
+ DOMPurify.removeHook = function (entryPoint) {
1324
+ return arrayPop(hooks[entryPoint]);
1325
+ };
1326
+ DOMPurify.removeHooks = function (entryPoint) {
1327
+ hooks[entryPoint] = [];
1328
+ };
1329
+ DOMPurify.removeAllHooks = function () {
1330
+ hooks = _createHooksMap();
1331
+ };
1332
+ return DOMPurify;
1333
+ }
1334
+ var purify = createDOMPurify();
1954
1335
 
1955
1336
  /**
1956
1337
  * This class represents all the constants needed in a MathType integration among different classes.
@@ -4365,7 +3746,7 @@ var translations = {
4365
3746
  // Get all the annotation content including the tags.
4366
3747
  let annotation = html.match(annotationRegex);
4367
3748
  // Sanitize html code without removing our supported MathML tags and attributes.
4368
- html = purifyExports.sanitize(html, {
3749
+ html = purify.sanitize(html, {
4369
3750
  ADD_TAGS: [
4370
3751
  "semantics",
4371
3752
  "annotation",
@@ -7701,7 +7082,7 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
7701
7082
  const isIOS = ContentManager.isIOS();
7702
7083
  this.iosSoftkeyboardOpened = false;
7703
7084
  this.iosMeasureUnit = ua.indexOf("crios") === -1 ? "%" : "vh";
7704
- this.iosDivHeight = `100%${this.iosMeasureUnit}`;
7085
+ this.iosDivHeight = `auto`;
7705
7086
  const deviceWidth = window.outerWidth;
7706
7087
  const deviceHeight = window.outerHeight;
7707
7088
  const landscape = deviceWidth > deviceHeight;
@@ -8116,7 +7497,6 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
8116
7497
  // iOS keyboard is a float div which can overlay the modal object.
8117
7498
  if (this.deviceProperties.isIOS) {
8118
7499
  this.iosSoftkeyboardOpened = false;
8119
- this.setContainerHeight(`${100 + this.iosMeasureUnit}`);
8120
7500
  }
8121
7501
  }
8122
7502
  if (!ContentManager.isEditorLoaded()) {
@@ -8493,8 +7873,6 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
8493
7873
  /**
8494
7874
  * Sets the modal dialog initial size.
8495
7875
  */ recalculateSize() {
8496
- this.wrapper.style.width = `${this.container.clientWidth - 12}px`;
8497
- this.wrapper.style.height = `${this.container.clientHeight - 38}px`;
8498
7876
  this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;
8499
7877
  }
8500
7878
  /**
@@ -8899,38 +8277,39 @@ var maxHoverIcon = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
8899
8277
  /**
8900
8278
  * Event handler that change container size when IOS soft keyboard is opened.
8901
8279
  */ handleOpenedIosSoftkeyboard() {
8902
- if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `100${this.iosMeasureUnit}`) {
8280
+ if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {
8903
8281
  if (this.portraitMode()) {
8904
- this.setContainerHeight(`63${this.iosMeasureUnit}`);
8282
+ this.setContainerHeight(`60${this.iosMeasureUnit}`);
8905
8283
  } else {
8906
- this.setContainerHeight(`40${this.iosMeasureUnit}`);
8284
+ this.setContainerHeight(`35${this.iosMeasureUnit}`);
8907
8285
  }
8908
8286
  }
8909
8287
  this.iosSoftkeyboardOpened = true;
8288
+ this.wrapper.style.flexGrow = "1";
8910
8289
  }
8911
8290
  /**
8912
8291
  * Event handler that change container size when IOS soft keyboard is closed.
8913
8292
  */ handleClosedIosSoftkeyboard() {
8914
8293
  this.iosSoftkeyboardOpened = false;
8915
- this.setContainerHeight(`100${this.iosMeasureUnit}`);
8294
+ this.wrapper.style.flexGrow = "1";
8916
8295
  }
8917
8296
  /**
8918
8297
  * Change container sizes when orientation is changed on iOS.
8919
8298
  */ orientationChangeIosSoftkeyboard() {
8920
8299
  if (this.iosSoftkeyboardOpened) {
8921
8300
  if (this.portraitMode()) {
8922
- this.setContainerHeight(`63${this.iosMeasureUnit}`);
8301
+ this.setContainerHeight(`65${this.iosMeasureUnit}`);
8923
8302
  } else {
8924
- this.setContainerHeight(`40${this.iosMeasureUnit}`);
8303
+ this.setContainerHeight(`45${this.iosMeasureUnit}`);
8925
8304
  }
8926
8305
  } else {
8927
- this.setContainerHeight(`100${this.iosMeasureUnit}`);
8306
+ this.wrapper.style.flexGrow = "1";
8928
8307
  }
8929
8308
  }
8930
8309
  /**
8931
8310
  * Change container sizes when orientation is changed on Android.
8932
8311
  */ orientationChangeAndroidSoftkeyboard() {
8933
- this.setContainerHeight("100%");
8312
+ this.wrapper.style.flexGrow = "1";
8934
8313
  }
8935
8314
  /**
8936
8315
  * Set iframe container height.
@@ -10791,7 +10170,7 @@ var mathIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adob
10791
10170
  var chemIcon = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->\n<svg version=\"1.1\" id=\"Layer_1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\"\n\t viewBox=\"0 0 40.3 49.5\" style=\"enable-background:new 0 0 40.3 49.5;\" xml:space=\"preserve\">\n<style type=\"text/css\">\n\t.st0{fill:#A4CF61;}\n</style>\n<path class=\"st0\" d=\"M39.2,12.1c0-1.9-1.1-3.6-2.7-4.4L24.5,0.9l0,0c-0.7-0.4-1.5-0.6-2.4-0.6c-0.9,0-1.7,0.2-2.4,0.6l0,0L2.3,10.8\n\tl0,0C0.9,11.7,0,13.2,0,14.9h0v19.6h0c0,1.7,0.9,3.3,2.3,4.1l0,0l17.4,9.9l0,0c0.7,0.4,1.5,0.6,2.4,0.6c0.9,0,1.7-0.2,2.4-0.6l0,0\n\tl12.2-6.9h0c1.5-0.8,2.6-2.5,2.6-4.3c0-2.7-2.2-4.9-4.9-4.9c-0.9,0-1.8,0.3-2.5,0.7l0,0l-9.7,5.6l-12.3-7V17.8l12.3-7l9.9,5.7l0,0\n\tc0.7,0.4,1.5,0.6,2.4,0.6C37,17,39.2,14.8,39.2,12.1\"/>\n</svg>\n";
10792
10171
 
10793
10172
  var name = "@wiris/mathtype-ckeditor5";
10794
- var version = "8.11.1";
10173
+ var version = "8.12.0";
10795
10174
  var description = "MathType Web for CKEditor5 editor";
10796
10175
  var keywords = [
10797
10176
  "chem",
@@ -10808,7 +10187,7 @@ var keywords = [
10808
10187
  "mathtype",
10809
10188
  "wiris"
10810
10189
  ];
10811
- var repository = "https://github.com/wiris/html-integrations/tree/stable/packages/mathtype-ckeditor5";
10190
+ var repository = "https://github.com/wiris/html-integrations/tree/master/packages/ckeditor5";
10812
10191
  var homepage = "https://www.wiris.com/";
10813
10192
  var bugs = {
10814
10193
  email: "support@wiris.com"
@@ -10838,7 +10217,7 @@ var scripts = {
10838
10217
  prepare: "npm run build:dist"
10839
10218
  };
10840
10219
  var dependencies = {
10841
- "@wiris/mathtype-html-integration-devkit": "1.17.5"
10220
+ "@wiris/mathtype-html-integration-devkit": "1.17.6"
10842
10221
  };
10843
10222
  var devDependencies = {
10844
10223
  "@ckeditor/ckeditor5-dev-build-tools": "^42.1.0",
@@ -10921,7 +10300,7 @@ class MathType extends Plugin {
10921
10300
  integrationProperties.managesLanguage = true;
10922
10301
  // etc
10923
10302
  // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.
10924
- // To avoid a wrong behaviour, this integration only starts if the workspace container exists.
10303
+ // To avoid a wrong behavior, this integration only starts if the workspace container exists.
10925
10304
  let integration;
10926
10305
  if (integrationProperties.target) {
10927
10306
  // Instance of the integration associated to this editor instance
@@ -11180,9 +10559,9 @@ class MathType extends Plugin {
11180
10559
  viewWriter.setAttribute("htmlContent", imgHtml, modelItem);
11181
10560
  }
11182
10561
  /* Although we use the HtmlDataProcessor to obtain the attributes,
11183
- * we must create a new EmptyElement which is independent of the
11184
- * DataProcessor being used by this editor instance
11185
- */ if (imgElement) {
10562
+ * we must create a new EmptyElement which is independent of the
10563
+ * DataProcessor being used by this editor instance
10564
+ */ if (imgElement) {
11186
10565
  return viewWriter.createEmptyElement("img", imgElement.getAttributes(), {
11187
10566
  renderUnsafeAttributes: [
11188
10567
  "src"
@@ -11224,7 +10603,7 @@ class MathType extends Plugin {
11224
10603
  function createDataString(modelItem, { writer: viewWriter }) {
11225
10604
  const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);
11226
10605
  // Load img element
11227
- let mathString = modelItem.getAttribute("htmlContent");
10606
+ let mathString = modelItem.getAttribute("htmlContent") || Parser.endParseSaveMode(modelItem.getAttribute("formula"));
11228
10607
  const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);
11229
10608
  return clone(viewWriter, sourceMathElement);
11230
10609
  }