@lango-project/lango-client 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! @license DOMPurify 3.4.17 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.17/LICENSE */
1
+ /*! @license DOMPurify 3.4.18 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.18/LICENSE */
2
2
  function _OverloadYield(e, d) {
3
3
  this.v = e, this.k = d;
4
4
  }
@@ -93,6 +93,7 @@ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator ||
93
93
  return this._invoke("return", e);
94
94
  };
95
95
  const entries = Object.entries;
96
+ const objectKeys = Object.keys;
96
97
  const setPrototypeOf = Object.setPrototypeOf;
97
98
  const isFrozen = Object.isFrozen;
98
99
  const getPrototypeOf = Object.getPrototypeOf;
@@ -118,7 +119,6 @@ if (!construct) construct = function construct(Func) {
118
119
  return new Func(...args);
119
120
  };
120
121
  const arrayForEach = unapply(Array.prototype.forEach);
121
- Array.prototype.indexOf;
122
122
  const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
123
123
  const arrayPop = unapply(Array.prototype.pop);
124
124
  const arrayPush = unapply(Array.prototype.push);
@@ -140,7 +140,11 @@ const bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.pro
140
140
  const symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
141
141
  const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
142
142
  const objectToString = unapply(Object.prototype.toString);
143
- const regExpTest = unapply(RegExp.prototype.test);
143
+ const regExpTestRaw = RegExp.prototype.test;
144
+ const regExpTest = function regExpTest(regExp, value) {
145
+ if (regExp instanceof RegExp) regExp.lastIndex = 0;
146
+ return apply(regExpTestRaw, regExp, [value]);
147
+ };
144
148
  const typeErrorCreate = unconstruct(TypeError);
145
149
  /**
146
150
  * Creates a new function that calls the given function with a specified thisArg and arguments.
@@ -150,7 +154,6 @@ const typeErrorCreate = unconstruct(TypeError);
150
154
  */
151
155
  function unapply(func) {
152
156
  return function(thisArg) {
153
- if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
154
157
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
155
158
  return apply(func, thisArg, args);
156
159
  };
@@ -224,6 +227,19 @@ function clone(object) {
224
227
  return newObject;
225
228
  }
226
229
  /**
230
+ * Copy a flat lookup table
231
+ *
232
+ * @param set - The set to copy.
233
+ * @returns A new prototype-free set with the same entries.
234
+ */
235
+ function cloneSet(set) {
236
+ const newSet = create(null);
237
+ const keys = objectKeys(set);
238
+ let l = keys.length;
239
+ while (l--) newSet[keys[l]] = set[keys[l]];
240
+ return newSet;
241
+ }
242
+ /**
227
243
  * Convert non-node values into strings without depending on direct property access.
228
244
  *
229
245
  * @param value - The value to stringify.
@@ -292,6 +308,7 @@ function lookupAccessor(object, prop) {
292
308
  return null;
293
309
  }
294
310
  function isRegex(value) {
311
+ if (!value) return false;
295
312
  try {
296
313
  regExpTest(value, "");
297
314
  return true;
@@ -434,8 +451,6 @@ const svg$1 = freeze([
434
451
  "defs",
435
452
  "desc",
436
453
  "ellipse",
437
- "enterkeyhint",
438
- "exportparts",
439
454
  "filter",
440
455
  "font",
441
456
  "g",
@@ -443,14 +458,12 @@ const svg$1 = freeze([
443
458
  "glyphref",
444
459
  "hkern",
445
460
  "image",
446
- "inputmode",
447
461
  "line",
448
462
  "lineargradient",
449
463
  "marker",
450
464
  "mask",
451
465
  "metadata",
452
466
  "mpath",
453
- "part",
454
467
  "path",
455
468
  "pattern",
456
469
  "polygon",
@@ -950,6 +963,7 @@ const xml = freeze([
950
963
  const MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
951
964
  const ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
952
965
  const TMPLIT_EXPR = seal(/\${[\w\W]*/g);
966
+ const TMPL_MARKER_SERIALIZED = seal(/{{|}}|\${|<%|%>|&lt;%|%&gt;/);
953
967
  const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
954
968
  const ARIA_ATTR = seal(/^aria-[\-\w]+$/);
955
969
  const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
@@ -961,19 +975,15 @@ const ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
961
975
  const COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
962
976
  const FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
963
977
  const SELF_CLOSING_TAG = seal(/\/>/i);
978
+ const ATTR_VALUE_BREAKOUT = seal(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i);
979
+ const LEADING_WHITESPACE = seal(/^[\r\n\t ]+/);
964
980
  const NODE_TYPE = {
965
981
  element: 1,
966
- attribute: 2,
967
982
  text: 3,
968
- cdataSection: 4,
969
- entityReference: 5,
970
- entityNode: 6,
971
983
  processingInstruction: 7,
972
984
  comment: 8,
973
985
  document: 9,
974
- documentType: 10,
975
- documentFragment: 11,
976
- notation: 12
986
+ documentFragment: 11
977
987
  };
978
988
  const LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
979
989
  "style",
@@ -1030,39 +1040,33 @@ const _createHooksMap = function _createHooksMap() {
1030
1040
  };
1031
1041
  };
1032
1042
  /**
1033
- * Resolve a set-valued configuration option: a fresh set built from
1034
- * cfg[key] when it is an own array property (seeded with a clone of
1035
- * options.base when given, case-normalized via options.transform),
1036
- * the fallback set otherwise.
1043
+ * Resolve a set-valued configuration option.
1037
1044
  *
1038
1045
  * @param cfg the cloned, prototype-free configuration object
1039
1046
  * @param key the configuration property to read
1040
1047
  * @param fallback the set to use when the option is absent or not an array
1041
- * @param options transform and optional base set to merge into
1042
- * @returns the resolved set
1048
+ * @param options case transform, and an optional base set to extend a copy of
1049
+ * @returns a fresh set built from cfg[key], or the fallback
1043
1050
  */
1044
1051
  const _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
1045
- return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
1052
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? cloneSet(options.base) : {}, cfg[key], options.transform) : fallback;
1046
1053
  };
1047
1054
  /**
1048
- * Resolve an object-valued configuration option: a prototype-free clone
1049
- * of cfg[key] when it is an own, truthy object property, else a fresh
1050
- * fallback built by makeFallback (fresh on every parse, so a previous
1051
- * parse can never leak state into the next one).
1055
+ * Resolve an object-valued configuration option.
1052
1056
  *
1053
1057
  * @param cfg the cloned, prototype-free configuration object
1054
1058
  * @param key the configuration property to read
1055
- * @param makeFallback builds the fallback value when the option is absent
1056
- * @returns the resolved object
1059
+ * @param fallback the read-only value to use when the option is absent
1060
+ * @returns a prototype-free clone of cfg[key], or the fallback
1057
1061
  */
1058
- const _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
1062
+ const _resolveObjectOption = function _resolveObjectOption(cfg, key, fallback) {
1059
1063
  const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
1060
- return value && typeof value === "object" ? clone(value) : makeFallback();
1064
+ return value && typeof value === "object" ? clone(value) : fallback;
1061
1065
  };
1062
1066
  function createDOMPurify() {
1063
1067
  let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
1064
1068
  const DOMPurify = (root) => createDOMPurify(root);
1065
- DOMPurify.version = "3.4.17";
1069
+ DOMPurify.version = "3.4.18";
1066
1070
  DOMPurify.removed = [];
1067
1071
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
1068
1072
  DOMPurify.isSupported = false;
@@ -1071,11 +1075,7 @@ function createDOMPurify() {
1071
1075
  let document = window.document;
1072
1076
  const originalDocument = document;
1073
1077
  const currentScript = originalDocument.currentScript;
1074
- window.DocumentFragment;
1075
- const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
1076
- window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
1077
- window.HTMLFormElement;
1078
- const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1078
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1079
1079
  const ElementPrototype = Element.prototype;
1080
1080
  const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
1081
1081
  const remove = lookupGetter(ElementPrototype, "remove");
@@ -1119,6 +1119,9 @@ function createDOMPurify() {
1119
1119
  IN_TRUSTED_TYPES_POLICY--;
1120
1120
  }
1121
1121
  };
1122
+ const _signOutput = function _signOutput(html) {
1123
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(html) : html;
1124
+ };
1122
1125
  const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
1123
1126
  _assertNotInTrustedTypesPolicy();
1124
1127
  IN_TRUSTED_TYPES_POLICY++;
@@ -1163,26 +1166,7 @@ function createDOMPurify() {
1163
1166
  ...mathMl,
1164
1167
  ...xml
1165
1168
  ]);
1166
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
1167
- tagNameCheck: {
1168
- writable: true,
1169
- configurable: false,
1170
- enumerable: true,
1171
- value: null
1172
- },
1173
- attributeNameCheck: {
1174
- writable: true,
1175
- configurable: false,
1176
- enumerable: true,
1177
- value: null
1178
- },
1179
- allowCustomizedBuiltInElements: {
1180
- writable: true,
1181
- configurable: false,
1182
- enumerable: true,
1183
- value: false
1184
- }
1185
- }));
1169
+ let CUSTOM_ELEMENT_HANDLING = null;
1186
1170
  let FORBID_TAGS = null;
1187
1171
  let FORBID_ATTR = null;
1188
1172
  const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
@@ -1219,7 +1203,7 @@ function createDOMPurify() {
1219
1203
  let KEEP_CONTENT = true;
1220
1204
  let IN_PLACE = false;
1221
1205
  let IN_PLACE_VISITED = null;
1222
- let USE_PROFILES = {};
1206
+ let USE_PROFILES = false;
1223
1207
  let FORBID_CONTENTS = null;
1224
1208
  const DEFAULT_FORBID_CONTENTS = addToSet({}, [
1225
1209
  "annotation-xml",
@@ -1286,16 +1270,17 @@ function createDOMPurify() {
1286
1270
  SVG_NAMESPACE,
1287
1271
  HTML_NAMESPACE
1288
1272
  ], stringToString);
1289
- const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
1273
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(addToSet({}, [
1290
1274
  "mi",
1291
1275
  "mo",
1292
1276
  "mn",
1293
1277
  "ms",
1294
1278
  "mtext"
1295
- ]);
1296
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1297
- const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
1298
- let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
1279
+ ]));
1280
+ let MATHML_TEXT_INTEGRATION_POINTS = null;
1281
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(addToSet({}, ["annotation-xml"]));
1282
+ let HTML_INTEGRATION_POINTS = null;
1283
+ const DEFAULT_CUSTOM_ELEMENT_HANDLING = freeze(create(null));
1299
1284
  const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
1300
1285
  "title",
1301
1286
  "style",
@@ -1319,7 +1304,6 @@ function createDOMPurify() {
1319
1304
  */
1320
1305
  const _parseConfig = function _parseConfig() {
1321
1306
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1322
- if (CONFIG && CONFIG === cfg) return;
1323
1307
  if (!cfg || typeof cfg !== "object") cfg = {};
1324
1308
  cfg = clone(cfg);
1325
1309
  PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
@@ -1336,8 +1320,8 @@ function createDOMPurify() {
1336
1320
  base: DEFAULT_DATA_URI_TAGS
1337
1321
  });
1338
1322
  FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
1339
- FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
1340
- FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
1323
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", create(null), { transform: transformCaseFunc });
1324
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", create(null), { transform: transformCaseFunc });
1341
1325
  USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
1342
1326
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
1343
1327
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
@@ -1356,9 +1340,9 @@ function createDOMPurify() {
1356
1340
  IN_PLACE = cfg.IN_PLACE || false;
1357
1341
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
1358
1342
  NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
1359
- MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
1360
- HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
1361
- const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
1343
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1344
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", DEFAULT_HTML_INTEGRATION_POINTS);
1345
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", DEFAULT_CUSTOM_ELEMENT_HANDLING);
1362
1346
  CUSTOM_ELEMENT_HANDLING = create(null);
1363
1347
  if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
1364
1348
  if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
@@ -1367,6 +1351,7 @@ function createDOMPurify() {
1367
1351
  if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
1368
1352
  if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
1369
1353
  if (USE_PROFILES) {
1354
+ if ((objectHasOwnProperty(cfg, "ALLOWED_TAGS") || objectHasOwnProperty(cfg, "ALLOWED_ATTR")) && typeof console !== "undefined" && typeof console.warn === "function") console.warn("DOMPurify: USE_PROFILES overrides ALLOWED_TAGS and ALLOWED_ATTR. Do not use these options together.");
1370
1355
  ALLOWED_TAGS = addToSet({}, text);
1371
1356
  ALLOWED_ATTR = create(null);
1372
1357
  if (USE_PROFILES.html === true) {
@@ -1394,19 +1379,19 @@ function createDOMPurify() {
1394
1379
  if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
1395
1380
  if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
1396
1381
  else if (arrayIsArray(cfg.ADD_TAGS)) {
1397
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
1382
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = cloneSet(ALLOWED_TAGS);
1398
1383
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1399
1384
  }
1400
1385
  }
1401
1386
  if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
1402
1387
  if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
1403
1388
  else if (arrayIsArray(cfg.ADD_ATTR)) {
1404
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
1389
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = cloneSet(ALLOWED_ATTR);
1405
1390
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1406
1391
  }
1407
1392
  }
1408
1393
  if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
1409
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
1394
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = cloneSet(FORBID_CONTENTS);
1410
1395
  addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
1411
1396
  }
1412
1397
  if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
@@ -1416,7 +1401,7 @@ function createDOMPurify() {
1416
1401
  "body"
1417
1402
  ]);
1418
1403
  if (ALLOWED_TAGS.table) {
1419
- addToSet(ALLOWED_TAGS, ["tbody"]);
1404
+ ALLOWED_TAGS.tbody = true;
1420
1405
  delete FORBID_TAGS.tbody;
1421
1406
  }
1422
1407
  if (cfg.TRUSTED_TYPES_POLICY) {
@@ -1437,8 +1422,7 @@ function createDOMPurify() {
1437
1422
  if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
1438
1423
  if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
1439
1424
  }
1440
- if (freeze) freeze(cfg);
1441
- CONFIG = cfg;
1425
+ CONFIG = freeze(cfg);
1442
1426
  };
1443
1427
  const ALL_SVG_TAGS = addToSet({}, [
1444
1428
  ...svg$1,
@@ -1450,39 +1434,39 @@ function createDOMPurify() {
1450
1434
  * Namespace rules for an element in the SVG namespace.
1451
1435
  *
1452
1436
  * @param tagName the element's lowercase tag name
1453
- * @param parent the (possibly simulated) parent node
1437
+ * @param parentNamespace the (possibly simulated) parent's namespace
1454
1438
  * @param parentTagName the parent's lowercase tag name
1455
1439
  * @returns true if a spec-compliant parser could produce this element
1456
1440
  */
1457
- const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
1458
- if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
1459
- if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1441
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parentNamespace, parentTagName) {
1442
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "svg";
1443
+ if (parentNamespace === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1460
1444
  return Boolean(ALL_SVG_TAGS[tagName]);
1461
1445
  };
1462
1446
  /**
1463
1447
  * Namespace rules for an element in the MathML namespace.
1464
1448
  *
1465
1449
  * @param tagName the element's lowercase tag name
1466
- * @param parent the (possibly simulated) parent node
1450
+ * @param parentNamespace the (possibly simulated) parent's namespace
1467
1451
  * @param parentTagName the parent's lowercase tag name
1468
1452
  * @returns true if a spec-compliant parser could produce this element
1469
1453
  */
1470
- const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
1471
- if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
1472
- if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1454
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parentNamespace, parentTagName) {
1455
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "math";
1456
+ if (parentNamespace === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1473
1457
  return Boolean(ALL_MATHML_TAGS[tagName]);
1474
1458
  };
1475
1459
  /**
1476
1460
  * Namespace rules for an element in the HTML namespace.
1477
1461
  *
1478
1462
  * @param tagName the element's lowercase tag name
1479
- * @param parent the (possibly simulated) parent node
1463
+ * @param parentNamespace the (possibly simulated) parent's namespace
1480
1464
  * @param parentTagName the parent's lowercase tag name
1481
1465
  * @returns true if a spec-compliant parser could produce this element
1482
1466
  */
1483
- const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
1484
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1485
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1467
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parentNamespace, parentTagName) {
1468
+ if (parentNamespace === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1469
+ if (parentNamespace === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1486
1470
  return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1487
1471
  };
1488
1472
  /**
@@ -1495,21 +1479,17 @@ function createDOMPurify() {
1495
1479
  const elementNamespace = _readNamespaceURI(element);
1496
1480
  const tagName = stringToLowerCase(_readNodeName(element));
1497
1481
  const parentNode = getParentNode(element);
1498
- let parent;
1499
- let parentTagName;
1482
+ let parentNamespace = NAMESPACE;
1483
+ let parentTagName = "template";
1500
1484
  if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
1501
- parent = { namespaceURI: _readNamespaceURI(parentNode) };
1485
+ parentNamespace = _readNamespaceURI(parentNode);
1502
1486
  parentTagName = stringToLowerCase(_readNodeName(parentNode));
1503
- } else {
1504
- parent = { namespaceURI: NAMESPACE };
1505
- parentTagName = "template";
1506
1487
  }
1507
1488
  if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
1508
- if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
1509
- if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
1510
- if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
1511
- if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
1512
- return false;
1489
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parentNamespace, parentTagName);
1490
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parentNamespace, parentTagName);
1491
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parentNamespace, parentTagName);
1492
+ return PARSER_MEDIA_TYPE === "application/xhtml+xml";
1513
1493
  };
1514
1494
  /**
1515
1495
  * _forceRemove
@@ -1526,17 +1506,10 @@ function createDOMPurify() {
1526
1506
  }
1527
1507
  };
1528
1508
  /**
1529
- * _stripAttributeNode
1530
- *
1531
- * Remove a single Attr node case/namespace-exactly on an attribute-teardown
1532
- * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
1533
- * HTML element in an HTML document and so silently misses a case-preserved
1534
- * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
1535
- * _removeAttribute() was fixed for, which a name-based call would reintroduce
1536
- * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
1537
- * record into DOMPurify.removed: the neutralize passes intentionally do not
1538
- * book-keep. A clobbered/detached node falls back to best-effort name-based
1539
- * removal.
1509
+ * Removes an Attr node as that exact node, without book-keeping. Name-based
1510
+ * removal lowercases the name in HTML documents and would miss a
1511
+ * case-preserved one such as `ONERROR`, so it is only the fallback for
1512
+ * clobbered or detached nodes.
1540
1513
  *
1541
1514
  * @param element the element to strip the attribute from
1542
1515
  * @param attribute the Attr node to remove
@@ -1566,12 +1539,7 @@ function createDOMPurify() {
1566
1539
  remove(child);
1567
1540
  } catch (_) {}
1568
1541
  });
1569
- const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
1570
- if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
1571
- const attribute = attributes[i];
1572
- const name = attribute && attribute.name;
1573
- if (typeof name === "string") _stripAttributeNode(root, attribute, name);
1574
- }
1542
+ if (_readNodeType(root) === NODE_TYPE.element) _stripAttributes(root, false);
1575
1543
  };
1576
1544
  /**
1577
1545
  * Removes an attribute, preferably as its exact Attr node: name-based
@@ -1592,14 +1560,10 @@ function createDOMPurify() {
1592
1560
  attribute: attr || null,
1593
1561
  from: element
1594
1562
  });
1595
- try {
1596
- if (attr) removeAttributeNode(element, attr);
1597
- else element.removeAttribute(name);
1598
- } catch (_) {
1599
- try {
1600
- element.removeAttribute(name);
1601
- } catch (_) {}
1602
- }
1563
+ if (attr) _stripAttributeNode(element, attr, name);
1564
+ else try {
1565
+ element.removeAttribute(name);
1566
+ } catch (_) {}
1603
1567
  if (name === "is") {
1604
1568
  if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
1605
1569
  _forceRemove(element);
@@ -1610,19 +1574,19 @@ function createDOMPurify() {
1610
1574
  }
1611
1575
  };
1612
1576
  /**
1613
- * Removes every attribute the configuration does not allow. Used to
1614
- * neutralize nodes discarded from an in-place tree.
1577
+ * Removes an element's attributes without book-keeping. Used to neutralize
1578
+ * nodes discarded from an in-place tree.
1615
1579
  *
1616
1580
  * @param element the element to strip
1581
+ * @param keepAllowed whether attributes on the allowlist stay
1617
1582
  */
1618
- const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1583
+ const _stripAttributes = function _stripAttributes(element, keepAllowed) {
1619
1584
  const attributes = getAttributes(element);
1620
1585
  if (!attributes) return;
1621
1586
  for (let i = attributes.length - 1; i >= 0; --i) {
1622
1587
  const attribute = attributes[i];
1623
1588
  const name = attribute && attribute.name;
1624
- if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
1625
- _stripAttributeNode(element, attribute, name);
1589
+ if (typeof name === "string" && !(keepAllowed && ALLOWED_ATTR[transformCaseFunc(name)])) _stripAttributeNode(element, attribute, name);
1626
1590
  }
1627
1591
  };
1628
1592
  /**
@@ -1657,7 +1621,7 @@ function createDOMPurify() {
1657
1621
  */
1658
1622
  const _neutralizeSubtree = function _neutralizeSubtree(root) {
1659
1623
  _walkTree(root, (node) => {
1660
- if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
1624
+ if (_readNodeType(node) === NODE_TYPE.element) _stripAttributes(node, true);
1661
1625
  });
1662
1626
  };
1663
1627
  /**
@@ -1688,7 +1652,7 @@ function createDOMPurify() {
1688
1652
  if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
1689
1653
  });
1690
1654
  arrayForEach(before, (node) => {
1691
- if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
1655
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripAttributes(node, true);
1692
1656
  });
1693
1657
  };
1694
1658
  /**
@@ -1761,9 +1725,7 @@ function createDOMPurify() {
1761
1725
  while (node = iterator.nextNode()) {
1762
1726
  if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
1763
1727
  if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
1764
- _sanitizeElements(node, root);
1765
- _sanitizeAttributes(node, root);
1766
- if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
1728
+ _sanitizeNode(node, root);
1767
1729
  }
1768
1730
  };
1769
1731
  /**
@@ -1795,7 +1757,7 @@ function createDOMPurify() {
1795
1757
  * and strips linkage attributes. It cannot undo a patch that already fired.
1796
1758
  *
1797
1759
  * TODO: if the shipped feature can patch through `for` on <label>/<output>,
1798
- * drop that pair here too (see test/declarative-patch-probe.html).
1760
+ * drop that pair here too.
1799
1761
  *
1800
1762
  * @param root the in-place root to sweep
1801
1763
  */
@@ -1831,7 +1793,7 @@ function createDOMPurify() {
1831
1793
  let leadingWhitespace = null;
1832
1794
  if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
1833
1795
  else {
1834
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1796
+ const matches = stringMatch(dirty, LEADING_WHITESPACE);
1835
1797
  leadingWhitespace = matches && matches[0];
1836
1798
  }
1837
1799
  if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) dirty = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head></head><body>" + dirty + "</body></html>";
@@ -1851,14 +1813,18 @@ function createDOMPurify() {
1851
1813
  return WHOLE_DOCUMENT ? doc.documentElement : body;
1852
1814
  };
1853
1815
  /**
1854
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1816
+ * Creates a NodeIterator over `root`. ownerDocument is read through the
1817
+ * cached getter: a form child named "ownerDocument" shadows the direct
1818
+ * read and would make createNodeIterator throw.
1855
1819
  *
1856
- * @param root The root element or node to start traversing on.
1820
+ * @param root The node to start traversing on.
1821
+ * @param characterDataOnly whether to skip elements
1857
1822
  * @return The created NodeIterator
1858
1823
  */
1859
1824
  const _createNodeIterator = function _createNodeIterator(root) {
1825
+ let characterDataOnly = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1860
1826
  const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
1861
- return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1827
+ return createNodeIterator.call(doc || root, root, (characterDataOnly ? 0 : NodeFilter.SHOW_ELEMENT) | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1862
1828
  };
1863
1829
  /**
1864
1830
  * Replace template expression syntax (mustache, ERB, template
@@ -1875,21 +1841,11 @@ function createDOMPurify() {
1875
1841
  return value;
1876
1842
  };
1877
1843
  /**
1878
- * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
1879
- * character data of an element subtree. Used as the final safety net for
1880
- * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
1881
- * which only form after text-node normalization (e.g. fragments split across
1882
- * stripped elements) cannot survive into a template-evaluating framework.
1883
- *
1884
- * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
1885
- * in place rather than round-tripping through innerHTML. This preserves
1886
- * descendant node references (important for IN_PLACE callers), avoids a
1887
- * serialize/reparse cycle, and reads literal character data — which means
1888
- * `<%...%>` in text content matches the ERB regex against its real bytes
1889
- * instead of the HTML-entity-escaped form innerHTML would produce.
1890
- *
1891
- * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
1892
- * attributes is performed during the per-node `_sanitizeAttributes` pass.
1844
+ * Strips template expressions from the character data under `node`,
1845
+ * template contents included. Runs after the walk, since an expression can
1846
+ * also form when a removed element leaves two text nodes adjacent. Works on
1847
+ * the nodes rather than on markup, which keeps node references intact and
1848
+ * sees `<%` unescaped. Attribute values are handled in _sanitizeAttributes.
1893
1849
  *
1894
1850
  * @param node The root element whose character data should be scrubbed.
1895
1851
  */
@@ -1902,23 +1858,15 @@ function createDOMPurify() {
1902
1858
  });
1903
1859
  };
1904
1860
  /**
1905
- * _scrubOwnCharacterData
1906
- *
1907
- * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
1908
- * strip template expressions from its own character data only. Does not
1909
- * enter <template>.content or attached shadow roots (NodeIterator never
1910
- * does). Used by _sanitizeShadowDOM, where every nested template content
1911
- * and shadow root is already walked - and therefore scrubbed - by its own
1912
- * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
1913
- * each nested fragment once per ancestor, which is quadratic in nesting
1914
- * depth.
1861
+ * Normalizes `node` and strips template expressions from its own character
1862
+ * data. Template contents and shadow roots are not entered, their own
1863
+ * _sanitizeShadowDOM call scrubs them.
1915
1864
  *
1916
1865
  * @param node The root whose own character data should be scrubbed.
1917
1866
  */
1918
1867
  const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
1919
1868
  node.normalize();
1920
- const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
1921
- const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
1869
+ const walker = _createNodeIterator(node, true);
1922
1870
  let currentNode = walker.nextNode();
1923
1871
  while (currentNode) {
1924
1872
  currentNode.data = _stripTemplateExpressions(currentNode.data);
@@ -1926,13 +1874,9 @@ function createDOMPurify() {
1926
1874
  }
1927
1875
  };
1928
1876
  /**
1929
- * _isClobbered
1930
- *
1931
- * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
1932
- * interface with [LegacyOverrideBuiltIns]; a descendant element with a
1933
- * `name` attribute matching a prototype property shadows that property
1934
- * on direct reads. We use this check at the IN_PLACE entry-point and
1935
- * during attribute sanitization to refuse clobbered forms.
1877
+ * Detects DOM clobbering on a form, the only element whose named children
1878
+ * shadow its own properties. Each probe compares a direct read with what
1879
+ * the property has to be.
1936
1880
  *
1937
1881
  * @param element element to check for clobbering attacks
1938
1882
  * @return true if clobbered, false if safe
@@ -1944,42 +1888,26 @@ function createDOMPurify() {
1944
1888
  return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.removeAttributeNode !== "function" || typeof element.getAttributeNode !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || element.nodeType !== getNodeType(element) || element.childNodes !== getChildNodes(element);
1945
1889
  };
1946
1890
  /**
1947
- * Checks whether the given value is a DocumentFragment from any realm.
1891
+ * Reads nodeType through the cached getter, so the result holds for nodes
1892
+ * from any realm (GHSA-4w3q-35jp-p934) and cannot be clobbered.
1948
1893
  *
1949
- * The realm-independent replacement reads `nodeType` through the cached
1950
- * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
1951
- * constant (11). nodeType is a numeric value resolved from the node's
1952
- * internal slot, identical across realms for the same kind of node.
1953
- *
1954
- * @param value object to check
1955
- * @return true if value is a DocumentFragment-shaped node from any realm
1894
+ * @param value anything
1895
+ * @return the node type, or null if value is not a DOM node
1956
1896
  */
1957
- const _isDocumentFragment = function _isDocumentFragment(value) {
1958
- if (!getNodeType || typeof value !== "object" || value === null) return false;
1897
+ const _nodeTypeOf = function _nodeTypeOf(value) {
1898
+ if (!getNodeType || typeof value !== "object" || value === null) return null;
1959
1899
  try {
1960
- return getNodeType(value) === NODE_TYPE.documentFragment;
1900
+ const nodeType = getNodeType(value);
1901
+ return typeof nodeType === "number" ? nodeType : null;
1961
1902
  } catch (_) {
1962
- return false;
1903
+ return null;
1963
1904
  }
1964
1905
  };
1965
- /**
1966
- * Checks whether the given object is a DOM node, including nodes that
1967
- * originate from a different window/realm (e.g. an iframe's
1968
- * contentDocument). The previous `value instanceof Node` check was
1969
- * realm-bound: nodes from a different window failed it, causing
1970
- * sanitize() to silently stringify them and reset IN_PLACE to false,
1971
- * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
1972
- *
1973
- * @param value object to check whether it's a DOM node
1974
- * @return true if value is a DOM node from any realm
1975
- */
1906
+ const _isDocumentFragment = function _isDocumentFragment(value) {
1907
+ return _nodeTypeOf(value) === NODE_TYPE.documentFragment;
1908
+ };
1976
1909
  const _isNode = function _isNode(value) {
1977
- if (!getNodeType || typeof value !== "object" || value === null) return false;
1978
- try {
1979
- return typeof getNodeType(value) === "number";
1980
- } catch (_) {
1981
- return false;
1982
- }
1910
+ return _nodeTypeOf(value) !== null;
1983
1911
  };
1984
1912
  function _executeHooks(hooks, currentNode, data) {
1985
1913
  if (hooks.length === 0) return;
@@ -1995,13 +1923,14 @@ function createDOMPurify() {
1995
1923
  *
1996
1924
  * @param currentNode the node to inspect
1997
1925
  * @param tagName the node's transformCaseFunc'd tag name
1926
+ * @param nodeType the node's type, read through the cached getter
1998
1927
  * @return true if the node must be removed
1999
1928
  */
2000
- const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
2001
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
2002
- if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && _readNodeType(currentNode) === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
2003
- if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
2004
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
1929
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName, nodeType) {
1930
+ if (SAFE_FOR_XML && nodeType === NODE_TYPE.element && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
1931
+ if (SAFE_FOR_XML && LITERAL_TEXT_ELEMENTS[tagName] && nodeType === NODE_TYPE.element && _readNamespaceURI(currentNode) === HTML_NAMESPACE && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent))) return true;
1932
+ if (nodeType === NODE_TYPE.processingInstruction) return true;
1933
+ if (SAFE_FOR_XML && nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
2005
1934
  return false;
2006
1935
  };
2007
1936
  /**
@@ -2025,17 +1954,9 @@ function createDOMPurify() {
2025
1954
  return false;
2026
1955
  };
2027
1956
  /**
2028
- * Handle a node whose tag is forbidden or not allowlisted: keep
2029
- * allowed custom elements (false return exits _sanitizeElements
2030
- * early - the namespace and fallback-tag removal checks are
2031
- * intentionally skipped for kept custom elements), else hoist
2032
- * content per KEEP_CONTENT and remove.
2033
- *
2034
- * A kept custom element is the ONLY case in which this function
2035
- * returns false, so the caller uses that return value to run the
2036
- * afterSanitizeElements hook on the kept element and keep the
2037
- * element-hook lifecycle consistent with normal allowlisted
2038
- * elements (GHSA-c2j3-45gr-mqc4).
1957
+ * Handles a node whose tag is forbidden or not allowlisted: hoists its
1958
+ * content per KEEP_CONTENT and removes it. The one exception is a custom
1959
+ * element allowed via CUSTOM_ELEMENT_HANDLING, which is kept.
2039
1960
  *
2040
1961
  * @param currentNode the disallowed node
2041
1962
  * @param tagName the node's transformCaseFunc'd tag name
@@ -2058,11 +1979,9 @@ function createDOMPurify() {
2058
1979
  return true;
2059
1980
  };
2060
1981
  /**
2061
- * Fork a hook-mutable allowlist off its shared binding the first time a
2062
- * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
2063
- * hook cannot widen the per-instance default or the setConfig binding by
2064
- * reference and leak past the call. Returns the set unchanged once it is
2065
- * already call-local, so repeated calls across elements are idempotent.
1982
+ * Forks an allowlist off its shared binding (the instance default or the
1983
+ * setConfig() capture) before a hook sees it, so a hook's widening stays
1984
+ * within the call. A set that is already call-local is returned as is.
2066
1985
  *
2067
1986
  * @param hookList the uponSanitize* hook array for this event
2068
1987
  * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
@@ -2073,7 +1992,7 @@ function createDOMPurify() {
2073
1992
  */
2074
1993
  const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
2075
1994
  if (hookList.length === 0) return set;
2076
- return set === defaultSet || set === setConfigSet ? clone(set) : set;
1995
+ return set === defaultSet || set === setConfigSet ? cloneSet(set) : set;
2077
1996
  };
2078
1997
  /**
2079
1998
  * A hook may have detached the node it was called for. If so, treat it as
@@ -2107,13 +2026,14 @@ function createDOMPurify() {
2107
2026
  return true;
2108
2027
  }
2109
2028
  const tagName = transformCaseFunc(_readNodeName(currentNode));
2029
+ const nodeType = _readNodeType(currentNode);
2110
2030
  ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
2111
2031
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
2112
2032
  tagName,
2113
2033
  allowedTags: ALLOWED_TAGS
2114
2034
  });
2115
2035
  if (_handleHookDetachedNode(currentNode, root)) return true;
2116
- if (_isUnsafeNode(currentNode, tagName)) {
2036
+ if (_isUnsafeNode(currentNode, tagName, nodeType)) {
2117
2037
  _forceRemove(currentNode);
2118
2038
  return true;
2119
2039
  }
@@ -2125,7 +2045,7 @@ function createDOMPurify() {
2125
2045
  }
2126
2046
  return removed;
2127
2047
  }
2128
- if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2048
+ if (nodeType === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2129
2049
  _forceRemove(currentNode);
2130
2050
  return true;
2131
2051
  }
@@ -2133,9 +2053,10 @@ function createDOMPurify() {
2133
2053
  _forceRemove(currentNode);
2134
2054
  return true;
2135
2055
  }
2136
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
2137
- const content = _stripTemplateExpressions(currentNode.textContent);
2138
- if (currentNode.textContent !== content) {
2056
+ if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
2057
+ const text = currentNode.textContent;
2058
+ const content = _stripTemplateExpressions(text);
2059
+ if (text !== content) {
2139
2060
  arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
2140
2061
  currentNode.textContent = content;
2141
2062
  }
@@ -2160,9 +2081,10 @@ function createDOMPurify() {
2160
2081
  if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
2161
2082
  if (!nameIsPermitted) return _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value);
2162
2083
  if (URI_SAFE_ATTRIBUTES[lcName]) return true;
2163
- if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2084
+ const compactValue = stringReplace(value, ATTR_WHITESPACE$1, "");
2085
+ if (regExpTest(IS_ALLOWED_URI$1, compactValue)) return true;
2164
2086
  if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
2165
- if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2087
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, compactValue)) return true;
2166
2088
  return !value;
2167
2089
  };
2168
2090
  const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
@@ -2206,21 +2128,8 @@ function createDOMPurify() {
2206
2128
  return value;
2207
2129
  };
2208
2130
  /**
2209
- * Write a modified attribute value back onto the element. On
2210
- * success, re-probe for clobbering introduced by the new value and
2211
- * remove the element when found; otherwise, when this writeback is the
2212
- * recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
2213
- * removal entry that path recorded so it does not show as removed. On
2214
- * failure, remove the attribute instead.
2215
- *
2216
- * Returns true only on a clean write (the value was set and the new value
2217
- * introduced no clobbering). The caller uses that, together with its own
2218
- * knowledge of whether this attribute pushed a DOMPurify.removed record, to
2219
- * decide whether to pop that record. The pop must happen ONLY for the
2220
- * named-prop remove-and-recreate; popping on any other value change (trim,
2221
- * template scrubbing, Trusted Types) would consume an unrelated _forceRemove
2222
- * subtree-cleanup record and let that detached subtree keep a live event
2223
- * handler through the IN_PLACE neutralization pass (SO-001).
2131
+ * Writes a changed attribute value back. If the new value clobbers, the
2132
+ * element is removed; if the write fails, the attribute is.
2224
2133
  *
2225
2134
  * @param currentNode the element carrying the attribute
2226
2135
  * @param name the attribute name as present on the element
@@ -2243,20 +2152,17 @@ function createDOMPurify() {
2243
2152
  }
2244
2153
  };
2245
2154
  /**
2246
- * _isUnsafeAttributeValue
2247
- *
2248
- * Value-based attribute checks that the attribute walk applies before any
2249
- * hook can force-keep an attribute, shared with the public
2250
- * isValidAttribute() so that it never approves a value sanitize() would
2251
- * strip.
2155
+ * Value checks that apply before a hook can force-keep an attribute. Also
2156
+ * used by isValidAttribute(), so it never approves a value that sanitize()
2157
+ * would strip.
2252
2158
  *
2253
2159
  * @param name the attribute name as found on the node (case preserved)
2254
2160
  * @param value the attribute value
2255
2161
  * @returns true if the attribute must be removed because of its value
2256
2162
  */
2257
2163
  const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
2258
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
2259
- return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
2164
+ if (SAFE_FOR_XML && regExpTest(ATTR_VALUE_BREAKOUT, value)) return true;
2165
+ return stringToLowerCase(name) === "attributename" && stringIndexOf(value, "href") !== -1;
2260
2166
  };
2261
2167
  /**
2262
2168
  * _sanitizeAttributes
@@ -2283,7 +2189,7 @@ function createDOMPurify() {
2283
2189
  forceKeepAttr: void 0
2284
2190
  };
2285
2191
  let l = attributes.length;
2286
- const lcTag = transformCaseFunc(currentNode.nodeName);
2192
+ const lcTag = transformCaseFunc(_readNodeName(currentNode));
2287
2193
  while (l--) {
2288
2194
  const attr = attributes[l];
2289
2195
  const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
@@ -2329,6 +2235,18 @@ function createDOMPurify() {
2329
2235
  _handleHookDetachedNode(currentNode, root);
2330
2236
  };
2331
2237
  /**
2238
+ * Sanitizes one node: the node itself, its attributes and, for a
2239
+ * template, its content.
2240
+ *
2241
+ * @param node the node to sanitize
2242
+ * @param root the current walk root
2243
+ */
2244
+ const _sanitizeNode = function _sanitizeNode(node, root) {
2245
+ _sanitizeElements(node, root);
2246
+ _sanitizeAttributes(node, root);
2247
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
2248
+ };
2249
+ /**
2332
2250
  * _sanitizeShadowDOM
2333
2251
  *
2334
2252
  * @param fragment to iterate over recursively
@@ -2339,9 +2257,7 @@ function createDOMPurify() {
2339
2257
  _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
2340
2258
  while (shadowNode = shadowIterator.nextNode()) {
2341
2259
  _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
2342
- _sanitizeElements(shadowNode, fragment);
2343
- _sanitizeAttributes(shadowNode, fragment);
2344
- if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
2260
+ _sanitizeNode(shadowNode, fragment);
2345
2261
  if (_readNodeType(shadowNode) === NODE_TYPE.element) {
2346
2262
  const innerSr = getShadowRoot(shadowNode);
2347
2263
  if (_isDocumentFragment(innerSr)) {
@@ -2417,8 +2333,6 @@ function createDOMPurify() {
2417
2333
  ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2418
2334
  ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2419
2335
  } else _parseConfig(cfg);
2420
- if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
2421
- if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
2422
2336
  DOMPurify.removed = [];
2423
2337
  const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
2424
2338
  let inPlaceNodes = [];
@@ -2447,7 +2361,7 @@ function createDOMPurify() {
2447
2361
  else body.appendChild(importedNode);
2448
2362
  _sanitizeAttachedShadowRoots(body);
2449
2363
  } else {
2450
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
2364
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return _signOutput(dirty);
2451
2365
  body = _initDocument(dirty);
2452
2366
  if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
2453
2367
  }
@@ -2456,11 +2370,7 @@ function createDOMPurify() {
2456
2370
  try {
2457
2371
  if (inPlace) _sanitizeAttachedShadowRoots(dirty);
2458
2372
  const nodeIterator = _createNodeIterator(walkRoot);
2459
- while (currentNode = nodeIterator.nextNode()) {
2460
- _sanitizeElements(currentNode, walkRoot);
2461
- _sanitizeAttributes(currentNode, walkRoot);
2462
- if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
2463
- }
2373
+ while (currentNode = nodeIterator.nextNode()) _sanitizeNode(currentNode, walkRoot);
2464
2374
  if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
2465
2375
  } catch (error) {
2466
2376
  if (inPlace) {
@@ -2485,10 +2395,14 @@ function createDOMPurify() {
2485
2395
  if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
2486
2396
  return returnNode;
2487
2397
  }
2488
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2398
+ const serialize = () => WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2399
+ let serializedHTML = serialize();
2400
+ if (SAFE_FOR_TEMPLATES && regExpTest(TMPL_MARKER_SERIALIZED, serializedHTML)) {
2401
+ _scrubOwnCharacterData(body);
2402
+ serializedHTML = serialize();
2403
+ }
2489
2404
  if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
2490
- if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
2491
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
2405
+ return _signOutput(serializedHTML);
2492
2406
  };
2493
2407
  DOMPurify.setConfig = function() {
2494
2408
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};