@mulmoclaude/core 6.0.1 → 7.1.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.
Files changed (43) hide show
  1. package/dist/collection/index.cjs +1 -1
  2. package/dist/collection/index.js +1 -1
  3. package/dist/collection/registry/server/index.cjs +6 -6
  4. package/dist/collection/registry/server/index.js +6 -6
  5. package/dist/collection/server/index.cjs +1 -1
  6. package/dist/collection/server/index.js +1 -1
  7. package/dist/collection-watchers/index.cjs +2 -2
  8. package/dist/collection-watchers/index.js +2 -2
  9. package/dist/feeds/server/index.cjs +4 -4
  10. package/dist/feeds/server/index.js +4 -4
  11. package/dist/files/index.cjs +11 -31
  12. package/dist/files/index.cjs.map +1 -1
  13. package/dist/files/index.d.ts +1 -0
  14. package/dist/files/index.js +4 -28
  15. package/dist/files/index.js.map +1 -1
  16. package/dist/files/withinRoot.d.ts +7 -0
  17. package/dist/google/index.cjs +3 -3
  18. package/dist/google/index.js +3 -3
  19. package/dist/plugin-vue/index.cjs +181 -267
  20. package/dist/plugin-vue/index.cjs.map +1 -1
  21. package/dist/plugin-vue/index.js +181 -267
  22. package/dist/plugin-vue/index.js.map +1 -1
  23. package/dist/remote-host/server/index.cjs +1 -1
  24. package/dist/remote-host/server/index.js +1 -1
  25. package/dist/{server-CQ88wv71.cjs → server-CnCUBmSn.cjs} +5 -5
  26. package/dist/{server-CQ88wv71.cjs.map → server-CnCUBmSn.cjs.map} +1 -1
  27. package/dist/{server-Dh7pgRRg.js → server-Dp5KWarO.js} +5 -5
  28. package/dist/{server-Dh7pgRRg.js.map → server-Dp5KWarO.js.map} +1 -1
  29. package/dist/whisper/index.cjs +1 -1
  30. package/dist/whisper/index.js +1 -1
  31. package/dist/wiki/index.cjs +1 -1
  32. package/dist/wiki/index.js +1 -1
  33. package/dist/wiki/server/fs.d.ts +0 -2
  34. package/dist/wiki/server/index.cjs +64 -47
  35. package/dist/wiki/server/index.cjs.map +1 -1
  36. package/dist/wiki/server/index.js +65 -48
  37. package/dist/wiki/server/index.js.map +1 -1
  38. package/dist/wiki/server/locations.d.ts +10 -0
  39. package/dist/withinRoot-Bbj6E-Lf.js +84 -0
  40. package/dist/withinRoot-Bbj6E-Lf.js.map +1 -0
  41. package/dist/withinRoot-FLjxC8oP.cjs +121 -0
  42. package/dist/withinRoot-FLjxC8oP.cjs.map +1 -0
  43. package/package.json +9 -9
@@ -131,7 +131,7 @@ IconGlyph.props = {
131
131
  fontClass: String
132
132
  };
133
133
  // ../../node_modules/dompurify/dist/purify.es.mjs
134
- /*! @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 */
134
+ /*! @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 */
135
135
  function _OverloadYield(e, d) {
136
136
  this.v = e, this.k = d;
137
137
  }
@@ -226,6 +226,7 @@ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator ||
226
226
  return this._invoke("return", e);
227
227
  };
228
228
  var entries = Object.entries;
229
+ var objectKeys = Object.keys;
229
230
  var setPrototypeOf = Object.setPrototypeOf;
230
231
  var isFrozen = Object.isFrozen;
231
232
  var getPrototypeOf = Object.getPrototypeOf;
@@ -251,7 +252,6 @@ if (!construct) construct = function construct(Func) {
251
252
  return new Func(...args);
252
253
  };
253
254
  var arrayForEach = unapply(Array.prototype.forEach);
254
- Array.prototype.indexOf;
255
255
  var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
256
256
  var arrayPop = unapply(Array.prototype.pop);
257
257
  var arrayPush = unapply(Array.prototype.push);
@@ -273,7 +273,11 @@ var bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.proto
273
273
  var symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
274
274
  var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
275
275
  var objectToString = unapply(Object.prototype.toString);
276
- var regExpTest = unapply(RegExp.prototype.test);
276
+ var regExpTestRaw = RegExp.prototype.test;
277
+ var regExpTest = function regExpTest(regExp, value) {
278
+ if (regExp instanceof RegExp) regExp.lastIndex = 0;
279
+ return apply(regExpTestRaw, regExp, [value]);
280
+ };
277
281
  var typeErrorCreate = unconstruct(TypeError);
278
282
  /**
279
283
  * Creates a new function that calls the given function with a specified thisArg and arguments.
@@ -283,7 +287,6 @@ var typeErrorCreate = unconstruct(TypeError);
283
287
  */
284
288
  function unapply(func) {
285
289
  return function(thisArg) {
286
- if (thisArg instanceof RegExp) thisArg.lastIndex = 0;
287
290
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) args[_key3 - 1] = arguments[_key3];
288
291
  return apply(func, thisArg, args);
289
292
  };
@@ -357,6 +360,19 @@ function clone(object) {
357
360
  return newObject;
358
361
  }
359
362
  /**
363
+ * Copy a flat lookup table
364
+ *
365
+ * @param set - The set to copy.
366
+ * @returns A new prototype-free set with the same entries.
367
+ */
368
+ function cloneSet(set) {
369
+ const newSet = create(null);
370
+ const keys = objectKeys(set);
371
+ let l = keys.length;
372
+ while (l--) newSet[keys[l]] = set[keys[l]];
373
+ return newSet;
374
+ }
375
+ /**
360
376
  * Convert non-node values into strings without depending on direct property access.
361
377
  *
362
378
  * @param value - The value to stringify.
@@ -425,6 +441,7 @@ function lookupAccessor(object, prop) {
425
441
  return null;
426
442
  }
427
443
  function isRegex(value) {
444
+ if (!value) return false;
428
445
  try {
429
446
  regExpTest(value, "");
430
447
  return true;
@@ -567,8 +584,6 @@ var svg$1 = freeze([
567
584
  "defs",
568
585
  "desc",
569
586
  "ellipse",
570
- "enterkeyhint",
571
- "exportparts",
572
587
  "filter",
573
588
  "font",
574
589
  "g",
@@ -576,14 +591,12 @@ var svg$1 = freeze([
576
591
  "glyphref",
577
592
  "hkern",
578
593
  "image",
579
- "inputmode",
580
594
  "line",
581
595
  "lineargradient",
582
596
  "marker",
583
597
  "mask",
584
598
  "metadata",
585
599
  "mpath",
586
- "part",
587
600
  "path",
588
601
  "pattern",
589
602
  "polygon",
@@ -1083,6 +1096,7 @@ var xml = freeze([
1083
1096
  var MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
1084
1097
  var ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
1085
1098
  var TMPLIT_EXPR = seal(/\${[\w\W]*/g);
1099
+ var TMPL_MARKER_SERIALIZED = seal(/{{|}}|\${|<%|%>|&lt;%|%&gt;/);
1086
1100
  var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
1087
1101
  var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
1088
1102
  var IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i);
@@ -1094,19 +1108,15 @@ var ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
1094
1108
  var COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
1095
1109
  var FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
1096
1110
  var SELF_CLOSING_TAG = seal(/\/>/i);
1111
+ var ATTR_VALUE_BREAKOUT = seal(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i);
1112
+ var LEADING_WHITESPACE = seal(/^[\r\n\t ]+/);
1097
1113
  var NODE_TYPE = {
1098
1114
  element: 1,
1099
- attribute: 2,
1100
1115
  text: 3,
1101
- cdataSection: 4,
1102
- entityReference: 5,
1103
- entityNode: 6,
1104
1116
  processingInstruction: 7,
1105
1117
  comment: 8,
1106
1118
  document: 9,
1107
- documentType: 10,
1108
- documentFragment: 11,
1109
- notation: 12
1119
+ documentFragment: 11
1110
1120
  };
1111
1121
  var LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, [
1112
1122
  "style",
@@ -1163,39 +1173,33 @@ var _createHooksMap = function _createHooksMap() {
1163
1173
  };
1164
1174
  };
1165
1175
  /**
1166
- * Resolve a set-valued configuration option: a fresh set built from
1167
- * cfg[key] when it is an own array property (seeded with a clone of
1168
- * options.base when given, case-normalized via options.transform),
1169
- * the fallback set otherwise.
1176
+ * Resolve a set-valued configuration option.
1170
1177
  *
1171
1178
  * @param cfg the cloned, prototype-free configuration object
1172
1179
  * @param key the configuration property to read
1173
1180
  * @param fallback the set to use when the option is absent or not an array
1174
- * @param options transform and optional base set to merge into
1175
- * @returns the resolved set
1181
+ * @param options case transform, and an optional base set to extend a copy of
1182
+ * @returns a fresh set built from cfg[key], or the fallback
1176
1183
  */
1177
1184
  var _resolveSetOption = function _resolveSetOption(cfg, key, fallback, options) {
1178
- return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
1185
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? cloneSet(options.base) : {}, cfg[key], options.transform) : fallback;
1179
1186
  };
1180
1187
  /**
1181
- * Resolve an object-valued configuration option: a prototype-free clone
1182
- * of cfg[key] when it is an own, truthy object property, else a fresh
1183
- * fallback built by makeFallback (fresh on every parse, so a previous
1184
- * parse can never leak state into the next one).
1188
+ * Resolve an object-valued configuration option.
1185
1189
  *
1186
1190
  * @param cfg the cloned, prototype-free configuration object
1187
1191
  * @param key the configuration property to read
1188
- * @param makeFallback builds the fallback value when the option is absent
1189
- * @returns the resolved object
1192
+ * @param fallback the read-only value to use when the option is absent
1193
+ * @returns a prototype-free clone of cfg[key], or the fallback
1190
1194
  */
1191
- var _resolveObjectOption = function _resolveObjectOption(cfg, key, makeFallback) {
1195
+ var _resolveObjectOption = function _resolveObjectOption(cfg, key, fallback) {
1192
1196
  const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
1193
- return value && typeof value === "object" ? clone(value) : makeFallback();
1197
+ return value && typeof value === "object" ? clone(value) : fallback;
1194
1198
  };
1195
1199
  function createDOMPurify() {
1196
1200
  let window = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
1197
1201
  const DOMPurify = (root) => createDOMPurify(root);
1198
- DOMPurify.version = "3.4.17";
1202
+ DOMPurify.version = "3.4.18";
1199
1203
  DOMPurify.removed = [];
1200
1204
  if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
1201
1205
  DOMPurify.isSupported = false;
@@ -1204,11 +1208,7 @@ function createDOMPurify() {
1204
1208
  let document = window.document;
1205
1209
  const originalDocument = document;
1206
1210
  const currentScript = originalDocument.currentScript;
1207
- window.DocumentFragment;
1208
- const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter;
1209
- window.NamedNodeMap === void 0 && (window.NamedNodeMap || window.MozNamedAttrMap);
1210
- window.HTMLFormElement;
1211
- const DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1211
+ const HTMLTemplateElement = window.HTMLTemplateElement, Node = window.Node, Element = window.Element, NodeFilter = window.NodeFilter, DOMParser = window.DOMParser, trustedTypes = window.trustedTypes;
1212
1212
  const ElementPrototype = Element.prototype;
1213
1213
  const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
1214
1214
  const remove = lookupGetter(ElementPrototype, "remove");
@@ -1252,6 +1252,9 @@ function createDOMPurify() {
1252
1252
  IN_TRUSTED_TYPES_POLICY--;
1253
1253
  }
1254
1254
  };
1255
+ const _signOutput = function _signOutput(html) {
1256
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(html) : html;
1257
+ };
1255
1258
  const _createTrustedScriptURL = function _createTrustedScriptURL(scriptUrl) {
1256
1259
  _assertNotInTrustedTypesPolicy();
1257
1260
  IN_TRUSTED_TYPES_POLICY++;
@@ -1296,26 +1299,7 @@ function createDOMPurify() {
1296
1299
  ...mathMl,
1297
1300
  ...xml
1298
1301
  ]);
1299
- let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
1300
- tagNameCheck: {
1301
- writable: true,
1302
- configurable: false,
1303
- enumerable: true,
1304
- value: null
1305
- },
1306
- attributeNameCheck: {
1307
- writable: true,
1308
- configurable: false,
1309
- enumerable: true,
1310
- value: null
1311
- },
1312
- allowCustomizedBuiltInElements: {
1313
- writable: true,
1314
- configurable: false,
1315
- enumerable: true,
1316
- value: false
1317
- }
1318
- }));
1302
+ let CUSTOM_ELEMENT_HANDLING = null;
1319
1303
  let FORBID_TAGS = null;
1320
1304
  let FORBID_ATTR = null;
1321
1305
  const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
@@ -1352,7 +1336,7 @@ function createDOMPurify() {
1352
1336
  let KEEP_CONTENT = true;
1353
1337
  let IN_PLACE = false;
1354
1338
  let IN_PLACE_VISITED = null;
1355
- let USE_PROFILES = {};
1339
+ let USE_PROFILES = false;
1356
1340
  let FORBID_CONTENTS = null;
1357
1341
  const DEFAULT_FORBID_CONTENTS = addToSet({}, [
1358
1342
  "annotation-xml",
@@ -1419,16 +1403,17 @@ function createDOMPurify() {
1419
1403
  SVG_NAMESPACE,
1420
1404
  HTML_NAMESPACE
1421
1405
  ], stringToString);
1422
- const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze([
1406
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(addToSet({}, [
1423
1407
  "mi",
1424
1408
  "mo",
1425
1409
  "mn",
1426
1410
  "ms",
1427
1411
  "mtext"
1428
- ]);
1429
- let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1430
- const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
1431
- let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
1412
+ ]));
1413
+ let MATHML_TEXT_INTEGRATION_POINTS = null;
1414
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(addToSet({}, ["annotation-xml"]));
1415
+ let HTML_INTEGRATION_POINTS = null;
1416
+ const DEFAULT_CUSTOM_ELEMENT_HANDLING = freeze(create(null));
1432
1417
  const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
1433
1418
  "title",
1434
1419
  "style",
@@ -1452,7 +1437,6 @@ function createDOMPurify() {
1452
1437
  */
1453
1438
  const _parseConfig = function _parseConfig() {
1454
1439
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1455
- if (CONFIG && CONFIG === cfg) return;
1456
1440
  if (!cfg || typeof cfg !== "object") cfg = {};
1457
1441
  cfg = clone(cfg);
1458
1442
  PARSER_MEDIA_TYPE = SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
@@ -1469,8 +1453,8 @@ function createDOMPurify() {
1469
1453
  base: DEFAULT_DATA_URI_TAGS
1470
1454
  });
1471
1455
  FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, { transform: transformCaseFunc });
1472
- FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), { transform: transformCaseFunc });
1473
- FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), { transform: transformCaseFunc });
1456
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", create(null), { transform: transformCaseFunc });
1457
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", create(null), { transform: transformCaseFunc });
1474
1458
  USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
1475
1459
  ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
1476
1460
  ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
@@ -1489,9 +1473,9 @@ function createDOMPurify() {
1489
1473
  IN_PLACE = cfg.IN_PLACE || false;
1490
1474
  IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
1491
1475
  NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
1492
- MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS));
1493
- HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS));
1494
- const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
1476
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(cfg, "MATHML_TEXT_INTEGRATION_POINTS", DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
1477
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(cfg, "HTML_INTEGRATION_POINTS", DEFAULT_HTML_INTEGRATION_POINTS);
1478
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", DEFAULT_CUSTOM_ELEMENT_HANDLING);
1495
1479
  CUSTOM_ELEMENT_HANDLING = create(null);
1496
1480
  if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
1497
1481
  if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
@@ -1500,6 +1484,7 @@ function createDOMPurify() {
1500
1484
  if (SAFE_FOR_TEMPLATES) ALLOW_DATA_ATTR = false;
1501
1485
  if (RETURN_DOM_FRAGMENT) RETURN_DOM = true;
1502
1486
  if (USE_PROFILES) {
1487
+ 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.");
1503
1488
  ALLOWED_TAGS = addToSet({}, text);
1504
1489
  ALLOWED_ATTR = create(null);
1505
1490
  if (USE_PROFILES.html === true) {
@@ -1527,19 +1512,19 @@ function createDOMPurify() {
1527
1512
  if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
1528
1513
  if (typeof cfg.ADD_TAGS === "function") EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
1529
1514
  else if (arrayIsArray(cfg.ADD_TAGS)) {
1530
- if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = clone(ALLOWED_TAGS);
1515
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) ALLOWED_TAGS = cloneSet(ALLOWED_TAGS);
1531
1516
  addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
1532
1517
  }
1533
1518
  }
1534
1519
  if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
1535
1520
  if (typeof cfg.ADD_ATTR === "function") EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
1536
1521
  else if (arrayIsArray(cfg.ADD_ATTR)) {
1537
- if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = clone(ALLOWED_ATTR);
1522
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) ALLOWED_ATTR = cloneSet(ALLOWED_ATTR);
1538
1523
  addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
1539
1524
  }
1540
1525
  }
1541
1526
  if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
1542
- if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = clone(FORBID_CONTENTS);
1527
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) FORBID_CONTENTS = cloneSet(FORBID_CONTENTS);
1543
1528
  addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
1544
1529
  }
1545
1530
  if (KEEP_CONTENT) ALLOWED_TAGS["#text"] = true;
@@ -1549,7 +1534,7 @@ function createDOMPurify() {
1549
1534
  "body"
1550
1535
  ]);
1551
1536
  if (ALLOWED_TAGS.table) {
1552
- addToSet(ALLOWED_TAGS, ["tbody"]);
1537
+ ALLOWED_TAGS.tbody = true;
1553
1538
  delete FORBID_TAGS.tbody;
1554
1539
  }
1555
1540
  if (cfg.TRUSTED_TYPES_POLICY) {
@@ -1570,8 +1555,7 @@ function createDOMPurify() {
1570
1555
  if (trustedTypesPolicy === void 0) trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
1571
1556
  if (trustedTypesPolicy && typeof emptyHTML === "string") emptyHTML = _createTrustedHTML("");
1572
1557
  }
1573
- if (freeze) freeze(cfg);
1574
- CONFIG = cfg;
1558
+ CONFIG = freeze(cfg);
1575
1559
  };
1576
1560
  const ALL_SVG_TAGS = addToSet({}, [
1577
1561
  ...svg$1,
@@ -1583,39 +1567,39 @@ function createDOMPurify() {
1583
1567
  * Namespace rules for an element in the SVG namespace.
1584
1568
  *
1585
1569
  * @param tagName the element's lowercase tag name
1586
- * @param parent the (possibly simulated) parent node
1570
+ * @param parentNamespace the (possibly simulated) parent's namespace
1587
1571
  * @param parentTagName the parent's lowercase tag name
1588
1572
  * @returns true if a spec-compliant parser could produce this element
1589
1573
  */
1590
- const _checkSvgNamespace = function _checkSvgNamespace(tagName, parent, parentTagName) {
1591
- if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "svg";
1592
- if (parent.namespaceURI === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1574
+ const _checkSvgNamespace = function _checkSvgNamespace(tagName, parentNamespace, parentTagName) {
1575
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "svg";
1576
+ if (parentNamespace === MATHML_NAMESPACE) return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1593
1577
  return Boolean(ALL_SVG_TAGS[tagName]);
1594
1578
  };
1595
1579
  /**
1596
1580
  * Namespace rules for an element in the MathML namespace.
1597
1581
  *
1598
1582
  * @param tagName the element's lowercase tag name
1599
- * @param parent the (possibly simulated) parent node
1583
+ * @param parentNamespace the (possibly simulated) parent's namespace
1600
1584
  * @param parentTagName the parent's lowercase tag name
1601
1585
  * @returns true if a spec-compliant parser could produce this element
1602
1586
  */
1603
- const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parent, parentTagName) {
1604
- if (parent.namespaceURI === HTML_NAMESPACE) return tagName === "math";
1605
- if (parent.namespaceURI === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1587
+ const _checkMathMlNamespace = function _checkMathMlNamespace(tagName, parentNamespace, parentTagName) {
1588
+ if (parentNamespace === HTML_NAMESPACE) return tagName === "math";
1589
+ if (parentNamespace === SVG_NAMESPACE) return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
1606
1590
  return Boolean(ALL_MATHML_TAGS[tagName]);
1607
1591
  };
1608
1592
  /**
1609
1593
  * Namespace rules for an element in the HTML namespace.
1610
1594
  *
1611
1595
  * @param tagName the element's lowercase tag name
1612
- * @param parent the (possibly simulated) parent node
1596
+ * @param parentNamespace the (possibly simulated) parent's namespace
1613
1597
  * @param parentTagName the parent's lowercase tag name
1614
1598
  * @returns true if a spec-compliant parser could produce this element
1615
1599
  */
1616
- const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parent, parentTagName) {
1617
- if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1618
- if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1600
+ const _checkHtmlNamespace = function _checkHtmlNamespace(tagName, parentNamespace, parentTagName) {
1601
+ if (parentNamespace === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) return false;
1602
+ if (parentNamespace === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) return false;
1619
1603
  return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1620
1604
  };
1621
1605
  /**
@@ -1628,21 +1612,17 @@ function createDOMPurify() {
1628
1612
  const elementNamespace = _readNamespaceURI(element);
1629
1613
  const tagName = stringToLowerCase(_readNodeName(element));
1630
1614
  const parentNode = getParentNode(element);
1631
- let parent;
1632
- let parentTagName;
1615
+ let parentNamespace = NAMESPACE;
1616
+ let parentTagName = "template";
1633
1617
  if (parentNode && _readNodeType(parentNode) === NODE_TYPE.element) {
1634
- parent = { namespaceURI: _readNamespaceURI(parentNode) };
1618
+ parentNamespace = _readNamespaceURI(parentNode);
1635
1619
  parentTagName = stringToLowerCase(_readNodeName(parentNode));
1636
- } else {
1637
- parent = { namespaceURI: NAMESPACE };
1638
- parentTagName = "template";
1639
1620
  }
1640
1621
  if (!ALLOWED_NAMESPACES[elementNamespace]) return false;
1641
- if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parent, parentTagName);
1642
- if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parent, parentTagName);
1643
- if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parent, parentTagName);
1644
- if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[elementNamespace]) return true;
1645
- return false;
1622
+ if (elementNamespace === SVG_NAMESPACE) return _checkSvgNamespace(tagName, parentNamespace, parentTagName);
1623
+ if (elementNamespace === MATHML_NAMESPACE) return _checkMathMlNamespace(tagName, parentNamespace, parentTagName);
1624
+ if (elementNamespace === HTML_NAMESPACE) return _checkHtmlNamespace(tagName, parentNamespace, parentTagName);
1625
+ return PARSER_MEDIA_TYPE === "application/xhtml+xml";
1646
1626
  };
1647
1627
  /**
1648
1628
  * _forceRemove
@@ -1659,17 +1639,10 @@ function createDOMPurify() {
1659
1639
  }
1660
1640
  };
1661
1641
  /**
1662
- * _stripAttributeNode
1663
- *
1664
- * Remove a single Attr node case/namespace-exactly on an attribute-teardown
1665
- * path. Name-based removeAttribute() ASCII-lowercases its lookup key for an
1666
- * HTML element in an HTML document and so silently misses a case-preserved
1667
- * handler (e.g. `ONERROR` off an XML/XHTML import) - the same defect
1668
- * _removeAttribute() was fixed for, which a name-based call would reintroduce
1669
- * on these IN_PLACE teardown paths. Unlike _removeAttribute this does not
1670
- * record into DOMPurify.removed: the neutralize passes intentionally do not
1671
- * book-keep. A clobbered/detached node falls back to best-effort name-based
1672
- * removal.
1642
+ * Removes an Attr node as that exact node, without book-keeping. Name-based
1643
+ * removal lowercases the name in HTML documents and would miss a
1644
+ * case-preserved one such as `ONERROR`, so it is only the fallback for
1645
+ * clobbered or detached nodes.
1673
1646
  *
1674
1647
  * @param element the element to strip the attribute from
1675
1648
  * @param attribute the Attr node to remove
@@ -1699,12 +1672,7 @@ function createDOMPurify() {
1699
1672
  remove(child);
1700
1673
  } catch (_) {}
1701
1674
  });
1702
- const attributes = _readNodeType(root) === NODE_TYPE.element ? getAttributes(root) : null;
1703
- if (attributes) for (let i = attributes.length - 1; i >= 0; --i) {
1704
- const attribute = attributes[i];
1705
- const name = attribute && attribute.name;
1706
- if (typeof name === "string") _stripAttributeNode(root, attribute, name);
1707
- }
1675
+ if (_readNodeType(root) === NODE_TYPE.element) _stripAttributes(root, false);
1708
1676
  };
1709
1677
  /**
1710
1678
  * Removes an attribute, preferably as its exact Attr node: name-based
@@ -1725,14 +1693,10 @@ function createDOMPurify() {
1725
1693
  attribute: attr || null,
1726
1694
  from: element
1727
1695
  });
1728
- try {
1729
- if (attr) removeAttributeNode(element, attr);
1730
- else element.removeAttribute(name);
1731
- } catch (_) {
1732
- try {
1733
- element.removeAttribute(name);
1734
- } catch (_) {}
1735
- }
1696
+ if (attr) _stripAttributeNode(element, attr, name);
1697
+ else try {
1698
+ element.removeAttribute(name);
1699
+ } catch (_) {}
1736
1700
  if (name === "is") {
1737
1701
  if (RETURN_DOM || RETURN_DOM_FRAGMENT) try {
1738
1702
  _forceRemove(element);
@@ -1743,19 +1707,19 @@ function createDOMPurify() {
1743
1707
  }
1744
1708
  };
1745
1709
  /**
1746
- * Removes every attribute the configuration does not allow. Used to
1747
- * neutralize nodes discarded from an in-place tree.
1710
+ * Removes an element's attributes without book-keeping. Used to neutralize
1711
+ * nodes discarded from an in-place tree.
1748
1712
  *
1749
1713
  * @param element the element to strip
1714
+ * @param keepAllowed whether attributes on the allowlist stay
1750
1715
  */
1751
- const _stripDisallowedAttributes = function _stripDisallowedAttributes(element) {
1716
+ const _stripAttributes = function _stripAttributes(element, keepAllowed) {
1752
1717
  const attributes = getAttributes(element);
1753
1718
  if (!attributes) return;
1754
1719
  for (let i = attributes.length - 1; i >= 0; --i) {
1755
1720
  const attribute = attributes[i];
1756
1721
  const name = attribute && attribute.name;
1757
- if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) continue;
1758
- _stripAttributeNode(element, attribute, name);
1722
+ if (typeof name === "string" && !(keepAllowed && ALLOWED_ATTR[transformCaseFunc(name)])) _stripAttributeNode(element, attribute, name);
1759
1723
  }
1760
1724
  };
1761
1725
  /**
@@ -1790,7 +1754,7 @@ function createDOMPurify() {
1790
1754
  */
1791
1755
  const _neutralizeSubtree = function _neutralizeSubtree(root) {
1792
1756
  _walkTree(root, (node) => {
1793
- if (_readNodeType(node) === NODE_TYPE.element) _stripDisallowedAttributes(node);
1757
+ if (_readNodeType(node) === NODE_TYPE.element) _stripAttributes(node, true);
1794
1758
  });
1795
1759
  };
1796
1760
  /**
@@ -1821,7 +1785,7 @@ function createDOMPurify() {
1821
1785
  if (_readNodeType(node) === NODE_TYPE.element) setAdd(reachable, node);
1822
1786
  });
1823
1787
  arrayForEach(before, (node) => {
1824
- if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripDisallowedAttributes(node);
1788
+ if (_readNodeType(node) === NODE_TYPE.element && !setHas(reachable, node)) _stripAttributes(node, true);
1825
1789
  });
1826
1790
  };
1827
1791
  /**
@@ -1894,9 +1858,7 @@ function createDOMPurify() {
1894
1858
  while (node = iterator.nextNode()) {
1895
1859
  if (!setHas(original, node) || setHas(IN_PLACE_VISITED, node)) continue;
1896
1860
  if (inShadow) _executeHooks(hooks.uponSanitizeShadowNode, node, null);
1897
- _sanitizeElements(node, root);
1898
- _sanitizeAttributes(node, root);
1899
- if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
1861
+ _sanitizeNode(node, root);
1900
1862
  }
1901
1863
  };
1902
1864
  /**
@@ -1928,7 +1890,7 @@ function createDOMPurify() {
1928
1890
  * and strips linkage attributes. It cannot undo a patch that already fired.
1929
1891
  *
1930
1892
  * TODO: if the shipped feature can patch through `for` on <label>/<output>,
1931
- * drop that pair here too (see test/declarative-patch-probe.html).
1893
+ * drop that pair here too.
1932
1894
  *
1933
1895
  * @param root the in-place root to sweep
1934
1896
  */
@@ -1964,7 +1926,7 @@ function createDOMPurify() {
1964
1926
  let leadingWhitespace = null;
1965
1927
  if (FORCE_BODY) dirty = "<remove></remove>" + dirty;
1966
1928
  else {
1967
- const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1929
+ const matches = stringMatch(dirty, LEADING_WHITESPACE);
1968
1930
  leadingWhitespace = matches && matches[0];
1969
1931
  }
1970
1932
  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>";
@@ -1984,14 +1946,18 @@ function createDOMPurify() {
1984
1946
  return WHOLE_DOCUMENT ? doc.documentElement : body;
1985
1947
  };
1986
1948
  /**
1987
- * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
1949
+ * Creates a NodeIterator over `root`. ownerDocument is read through the
1950
+ * cached getter: a form child named "ownerDocument" shadows the direct
1951
+ * read and would make createNodeIterator throw.
1988
1952
  *
1989
- * @param root The root element or node to start traversing on.
1953
+ * @param root The node to start traversing on.
1954
+ * @param characterDataOnly whether to skip elements
1990
1955
  * @return The created NodeIterator
1991
1956
  */
1992
1957
  const _createNodeIterator = function _createNodeIterator(root) {
1958
+ let characterDataOnly = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
1993
1959
  const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
1994
- return createNodeIterator.call(doc || root, root, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
1960
+ 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);
1995
1961
  };
1996
1962
  /**
1997
1963
  * Replace template expression syntax (mustache, ERB, template
@@ -2008,21 +1974,11 @@ function createDOMPurify() {
2008
1974
  return value;
2009
1975
  };
2010
1976
  /**
2011
- * Strip template-engine expressions ({{...}}, ${...}, <%...%>) from the
2012
- * character data of an element subtree. Used as the final safety net for
2013
- * SAFE_FOR_TEMPLATES on every DOM-returning code path so that expressions
2014
- * which only form after text-node normalization (e.g. fragments split across
2015
- * stripped elements) cannot survive into a template-evaluating framework.
2016
- *
2017
- * Walks text/comment/CDATA/processing-instruction nodes and mutates `.data`
2018
- * in place rather than round-tripping through innerHTML. This preserves
2019
- * descendant node references (important for IN_PLACE callers), avoids a
2020
- * serialize/reparse cycle, and reads literal character data — which means
2021
- * `<%...%>` in text content matches the ERB regex against its real bytes
2022
- * instead of the HTML-entity-escaped form innerHTML would produce.
2023
- *
2024
- * Attribute values are not visited here; SAFE_FOR_TEMPLATES handling for
2025
- * attributes is performed during the per-node `_sanitizeAttributes` pass.
1977
+ * Strips template expressions from the character data under `node`,
1978
+ * template contents included. Runs after the walk, since an expression can
1979
+ * also form when a removed element leaves two text nodes adjacent. Works on
1980
+ * the nodes rather than on markup, which keeps node references intact and
1981
+ * sees `<%` unescaped. Attribute values are handled in _sanitizeAttributes.
2026
1982
  *
2027
1983
  * @param node The root element whose character data should be scrubbed.
2028
1984
  */
@@ -2035,23 +1991,15 @@ function createDOMPurify() {
2035
1991
  });
2036
1992
  };
2037
1993
  /**
2038
- * _scrubOwnCharacterData
2039
- *
2040
- * Non-recursive core of _scrubTemplateExpressions: normalize `node` and
2041
- * strip template expressions from its own character data only. Does not
2042
- * enter <template>.content or attached shadow roots (NodeIterator never
2043
- * does). Used by _sanitizeShadowDOM, where every nested template content
2044
- * and shadow root is already walked - and therefore scrubbed - by its own
2045
- * recursive _sanitizeShadowDOM call; recursing here as well would rescrub
2046
- * each nested fragment once per ancestor, which is quadratic in nesting
2047
- * depth.
1994
+ * Normalizes `node` and strips template expressions from its own character
1995
+ * data. Template contents and shadow roots are not entered, their own
1996
+ * _sanitizeShadowDOM call scrubs them.
2048
1997
  *
2049
1998
  * @param node The root whose own character data should be scrubbed.
2050
1999
  */
2051
2000
  const _scrubOwnCharacterData = function _scrubOwnCharacterData(node) {
2052
2001
  node.normalize();
2053
- const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
2054
- const walker = createNodeIterator.call(doc || node, node, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION, null);
2002
+ const walker = _createNodeIterator(node, true);
2055
2003
  let currentNode = walker.nextNode();
2056
2004
  while (currentNode) {
2057
2005
  currentNode.data = _stripTemplateExpressions(currentNode.data);
@@ -2059,13 +2007,9 @@ function createDOMPurify() {
2059
2007
  }
2060
2008
  };
2061
2009
  /**
2062
- * _isClobbered
2063
- *
2064
- * Detect DOM-clobbering on HTMLFormElement nodes. Form is the only HTML
2065
- * interface with [LegacyOverrideBuiltIns]; a descendant element with a
2066
- * `name` attribute matching a prototype property shadows that property
2067
- * on direct reads. We use this check at the IN_PLACE entry-point and
2068
- * during attribute sanitization to refuse clobbered forms.
2010
+ * Detects DOM clobbering on a form, the only element whose named children
2011
+ * shadow its own properties. Each probe compares a direct read with what
2012
+ * the property has to be.
2069
2013
  *
2070
2014
  * @param element element to check for clobbering attacks
2071
2015
  * @return true if clobbered, false if safe
@@ -2077,42 +2021,26 @@ function createDOMPurify() {
2077
2021
  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);
2078
2022
  };
2079
2023
  /**
2080
- * Checks whether the given value is a DocumentFragment from any realm.
2024
+ * Reads nodeType through the cached getter, so the result holds for nodes
2025
+ * from any realm (GHSA-4w3q-35jp-p934) and cannot be clobbered.
2081
2026
  *
2082
- * The realm-independent replacement reads `nodeType` through the cached
2083
- * Node.prototype getter and compares to the DOCUMENT_FRAGMENT_NODE
2084
- * constant (11). nodeType is a numeric value resolved from the node's
2085
- * internal slot, identical across realms for the same kind of node.
2086
- *
2087
- * @param value object to check
2088
- * @return true if value is a DocumentFragment-shaped node from any realm
2027
+ * @param value anything
2028
+ * @return the node type, or null if value is not a DOM node
2089
2029
  */
2090
- const _isDocumentFragment = function _isDocumentFragment(value) {
2091
- if (!getNodeType || typeof value !== "object" || value === null) return false;
2030
+ const _nodeTypeOf = function _nodeTypeOf(value) {
2031
+ if (!getNodeType || typeof value !== "object" || value === null) return null;
2092
2032
  try {
2093
- return getNodeType(value) === NODE_TYPE.documentFragment;
2033
+ const nodeType = getNodeType(value);
2034
+ return typeof nodeType === "number" ? nodeType : null;
2094
2035
  } catch (_) {
2095
- return false;
2036
+ return null;
2096
2037
  }
2097
2038
  };
2098
- /**
2099
- * Checks whether the given object is a DOM node, including nodes that
2100
- * originate from a different window/realm (e.g. an iframe's
2101
- * contentDocument). The previous `value instanceof Node` check was
2102
- * realm-bound: nodes from a different window failed it, causing
2103
- * sanitize() to silently stringify them and reset IN_PLACE to false,
2104
- * returning the original node unsanitized. See GHSA-4w3q-35jp-p934.
2105
- *
2106
- * @param value object to check whether it's a DOM node
2107
- * @return true if value is a DOM node from any realm
2108
- */
2039
+ const _isDocumentFragment = function _isDocumentFragment(value) {
2040
+ return _nodeTypeOf(value) === NODE_TYPE.documentFragment;
2041
+ };
2109
2042
  const _isNode = function _isNode(value) {
2110
- if (!getNodeType || typeof value !== "object" || value === null) return false;
2111
- try {
2112
- return typeof getNodeType(value) === "number";
2113
- } catch (_) {
2114
- return false;
2115
- }
2043
+ return _nodeTypeOf(value) !== null;
2116
2044
  };
2117
2045
  function _executeHooks(hooks, currentNode, data) {
2118
2046
  if (hooks.length === 0) return;
@@ -2128,13 +2056,14 @@ function createDOMPurify() {
2128
2056
  *
2129
2057
  * @param currentNode the node to inspect
2130
2058
  * @param tagName the node's transformCaseFunc'd tag name
2059
+ * @param nodeType the node's type, read through the cached getter
2131
2060
  * @return true if the node must be removed
2132
2061
  */
2133
- const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName) {
2134
- if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) return true;
2135
- 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;
2136
- if (currentNode.nodeType === NODE_TYPE.processingInstruction) return true;
2137
- if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
2062
+ const _isUnsafeNode = function _isUnsafeNode(currentNode, tagName, nodeType) {
2063
+ 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;
2064
+ 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;
2065
+ if (nodeType === NODE_TYPE.processingInstruction) return true;
2066
+ if (SAFE_FOR_XML && nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) return true;
2138
2067
  return false;
2139
2068
  };
2140
2069
  /**
@@ -2158,17 +2087,9 @@ function createDOMPurify() {
2158
2087
  return false;
2159
2088
  };
2160
2089
  /**
2161
- * Handle a node whose tag is forbidden or not allowlisted: keep
2162
- * allowed custom elements (false return exits _sanitizeElements
2163
- * early - the namespace and fallback-tag removal checks are
2164
- * intentionally skipped for kept custom elements), else hoist
2165
- * content per KEEP_CONTENT and remove.
2166
- *
2167
- * A kept custom element is the ONLY case in which this function
2168
- * returns false, so the caller uses that return value to run the
2169
- * afterSanitizeElements hook on the kept element and keep the
2170
- * element-hook lifecycle consistent with normal allowlisted
2171
- * elements (GHSA-c2j3-45gr-mqc4).
2090
+ * Handles a node whose tag is forbidden or not allowlisted: hoists its
2091
+ * content per KEEP_CONTENT and removes it. The one exception is a custom
2092
+ * element allowed via CUSTOM_ELEMENT_HANDLING, which is kept.
2172
2093
  *
2173
2094
  * @param currentNode the disallowed node
2174
2095
  * @param tagName the node's transformCaseFunc'd tag name
@@ -2191,11 +2112,9 @@ function createDOMPurify() {
2191
2112
  return true;
2192
2113
  };
2193
2114
  /**
2194
- * Fork a hook-mutable allowlist off its shared binding the first time a
2195
- * (possibly lazily-installed) uponSanitize* hook is about to see it, so the
2196
- * hook cannot widen the per-instance default or the setConfig binding by
2197
- * reference and leak past the call. Returns the set unchanged once it is
2198
- * already call-local, so repeated calls across elements are idempotent.
2115
+ * Forks an allowlist off its shared binding (the instance default or the
2116
+ * setConfig() capture) before a hook sees it, so a hook's widening stays
2117
+ * within the call. A set that is already call-local is returned as is.
2199
2118
  *
2200
2119
  * @param hookList the uponSanitize* hook array for this event
2201
2120
  * @param set the current ALLOWED_TAGS / ALLOWED_ATTR binding
@@ -2206,7 +2125,7 @@ function createDOMPurify() {
2206
2125
  */
2207
2126
  const _forkSharedAllowlist = function _forkSharedAllowlist(hookList, set, defaultSet, setConfigSet) {
2208
2127
  if (hookList.length === 0) return set;
2209
- return set === defaultSet || set === setConfigSet ? clone(set) : set;
2128
+ return set === defaultSet || set === setConfigSet ? cloneSet(set) : set;
2210
2129
  };
2211
2130
  /**
2212
2131
  * A hook may have detached the node it was called for. If so, treat it as
@@ -2240,13 +2159,14 @@ function createDOMPurify() {
2240
2159
  return true;
2241
2160
  }
2242
2161
  const tagName = transformCaseFunc(_readNodeName(currentNode));
2162
+ const nodeType = _readNodeType(currentNode);
2243
2163
  ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
2244
2164
  _executeHooks(hooks.uponSanitizeElement, currentNode, {
2245
2165
  tagName,
2246
2166
  allowedTags: ALLOWED_TAGS
2247
2167
  });
2248
2168
  if (_handleHookDetachedNode(currentNode, root)) return true;
2249
- if (_isUnsafeNode(currentNode, tagName)) {
2169
+ if (_isUnsafeNode(currentNode, tagName, nodeType)) {
2250
2170
  _forceRemove(currentNode);
2251
2171
  return true;
2252
2172
  }
@@ -2258,7 +2178,7 @@ function createDOMPurify() {
2258
2178
  }
2259
2179
  return removed;
2260
2180
  }
2261
- if (_readNodeType(currentNode) === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2181
+ if (nodeType === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
2262
2182
  _forceRemove(currentNode);
2263
2183
  return true;
2264
2184
  }
@@ -2266,9 +2186,10 @@ function createDOMPurify() {
2266
2186
  _forceRemove(currentNode);
2267
2187
  return true;
2268
2188
  }
2269
- if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
2270
- const content = _stripTemplateExpressions(currentNode.textContent);
2271
- if (currentNode.textContent !== content) {
2189
+ if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
2190
+ const text = currentNode.textContent;
2191
+ const content = _stripTemplateExpressions(text);
2192
+ if (text !== content) {
2272
2193
  arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
2273
2194
  currentNode.textContent = content;
2274
2195
  }
@@ -2293,9 +2214,10 @@ function createDOMPurify() {
2293
2214
  if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) return true;
2294
2215
  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);
2295
2216
  if (URI_SAFE_ATTRIBUTES[lcName]) return true;
2296
- if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2217
+ const compactValue = stringReplace(value, ATTR_WHITESPACE$1, "");
2218
+ if (regExpTest(IS_ALLOWED_URI$1, compactValue)) return true;
2297
2219
  if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) return true;
2298
- if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) return true;
2220
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, compactValue)) return true;
2299
2221
  return !value;
2300
2222
  };
2301
2223
  const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, [
@@ -2339,21 +2261,8 @@ function createDOMPurify() {
2339
2261
  return value;
2340
2262
  };
2341
2263
  /**
2342
- * Write a modified attribute value back onto the element. On
2343
- * success, re-probe for clobbering introduced by the new value and
2344
- * remove the element when found; otherwise, when this writeback is the
2345
- * recreate half of the SANITIZE_NAMED_PROPS remove-and-recreate, pop the
2346
- * removal entry that path recorded so it does not show as removed. On
2347
- * failure, remove the attribute instead.
2348
- *
2349
- * Returns true only on a clean write (the value was set and the new value
2350
- * introduced no clobbering). The caller uses that, together with its own
2351
- * knowledge of whether this attribute pushed a DOMPurify.removed record, to
2352
- * decide whether to pop that record. The pop must happen ONLY for the
2353
- * named-prop remove-and-recreate; popping on any other value change (trim,
2354
- * template scrubbing, Trusted Types) would consume an unrelated _forceRemove
2355
- * subtree-cleanup record and let that detached subtree keep a live event
2356
- * handler through the IN_PLACE neutralization pass (SO-001).
2264
+ * Writes a changed attribute value back. If the new value clobbers, the
2265
+ * element is removed; if the write fails, the attribute is.
2357
2266
  *
2358
2267
  * @param currentNode the element carrying the attribute
2359
2268
  * @param name the attribute name as present on the element
@@ -2376,20 +2285,17 @@ function createDOMPurify() {
2376
2285
  }
2377
2286
  };
2378
2287
  /**
2379
- * _isUnsafeAttributeValue
2380
- *
2381
- * Value-based attribute checks that the attribute walk applies before any
2382
- * hook can force-keep an attribute, shared with the public
2383
- * isValidAttribute() so that it never approves a value sanitize() would
2384
- * strip.
2288
+ * Value checks that apply before a hook can force-keep an attribute. Also
2289
+ * used by isValidAttribute(), so it never approves a value that sanitize()
2290
+ * would strip.
2385
2291
  *
2386
2292
  * @param name the attribute name as found on the node (case preserved)
2387
2293
  * @param value the attribute value
2388
2294
  * @returns true if the attribute must be removed because of its value
2389
2295
  */
2390
2296
  const _isUnsafeAttributeValue = function _isUnsafeAttributeValue(name, value) {
2391
- if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) return true;
2392
- return stringToLowerCase(name) === "attributename" && stringMatch(value, "href") !== null;
2297
+ if (SAFE_FOR_XML && regExpTest(ATTR_VALUE_BREAKOUT, value)) return true;
2298
+ return stringToLowerCase(name) === "attributename" && stringIndexOf(value, "href") !== -1;
2393
2299
  };
2394
2300
  /**
2395
2301
  * _sanitizeAttributes
@@ -2416,7 +2322,7 @@ function createDOMPurify() {
2416
2322
  forceKeepAttr: void 0
2417
2323
  };
2418
2324
  let l = attributes.length;
2419
- const lcTag = transformCaseFunc(currentNode.nodeName);
2325
+ const lcTag = transformCaseFunc(_readNodeName(currentNode));
2420
2326
  while (l--) {
2421
2327
  const attr = attributes[l];
2422
2328
  const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
@@ -2462,6 +2368,18 @@ function createDOMPurify() {
2462
2368
  _handleHookDetachedNode(currentNode, root);
2463
2369
  };
2464
2370
  /**
2371
+ * Sanitizes one node: the node itself, its attributes and, for a
2372
+ * template, its content.
2373
+ *
2374
+ * @param node the node to sanitize
2375
+ * @param root the current walk root
2376
+ */
2377
+ const _sanitizeNode = function _sanitizeNode(node, root) {
2378
+ _sanitizeElements(node, root);
2379
+ _sanitizeAttributes(node, root);
2380
+ if (_isDocumentFragment(node.content)) _sanitizeShadowDOM2(node.content);
2381
+ };
2382
+ /**
2465
2383
  * _sanitizeShadowDOM
2466
2384
  *
2467
2385
  * @param fragment to iterate over recursively
@@ -2472,9 +2390,7 @@ function createDOMPurify() {
2472
2390
  _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
2473
2391
  while (shadowNode = shadowIterator.nextNode()) {
2474
2392
  _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
2475
- _sanitizeElements(shadowNode, fragment);
2476
- _sanitizeAttributes(shadowNode, fragment);
2477
- if (_isDocumentFragment(shadowNode.content)) _sanitizeShadowDOM2(shadowNode.content);
2393
+ _sanitizeNode(shadowNode, fragment);
2478
2394
  if (_readNodeType(shadowNode) === NODE_TYPE.element) {
2479
2395
  const innerSr = getShadowRoot(shadowNode);
2480
2396
  if (_isDocumentFragment(innerSr)) {
@@ -2550,8 +2466,6 @@ function createDOMPurify() {
2550
2466
  ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
2551
2467
  ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
2552
2468
  } else _parseConfig(cfg);
2553
- if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) ALLOWED_TAGS = clone(ALLOWED_TAGS);
2554
- if (hooks.uponSanitizeAttribute.length > 0) ALLOWED_ATTR = clone(ALLOWED_ATTR);
2555
2469
  DOMPurify.removed = [];
2556
2470
  const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
2557
2471
  let inPlaceNodes = [];
@@ -2580,7 +2494,7 @@ function createDOMPurify() {
2580
2494
  else body.appendChild(importedNode);
2581
2495
  _sanitizeAttachedShadowRoots(body);
2582
2496
  } else {
2583
- if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
2497
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && dirty.indexOf("<") === -1) return _signOutput(dirty);
2584
2498
  body = _initDocument(dirty);
2585
2499
  if (!body) return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
2586
2500
  }
@@ -2589,11 +2503,7 @@ function createDOMPurify() {
2589
2503
  try {
2590
2504
  if (inPlace) _sanitizeAttachedShadowRoots(dirty);
2591
2505
  const nodeIterator = _createNodeIterator(walkRoot);
2592
- while (currentNode = nodeIterator.nextNode()) {
2593
- _sanitizeElements(currentNode, walkRoot);
2594
- _sanitizeAttributes(currentNode, walkRoot);
2595
- if (_isDocumentFragment(currentNode.content)) _sanitizeShadowDOM2(currentNode.content);
2596
- }
2506
+ while (currentNode = nodeIterator.nextNode()) _sanitizeNode(currentNode, walkRoot);
2597
2507
  if (inPlace) _sanitizeUnvisitedNodes(dirty, inPlaceNodes);
2598
2508
  } catch (error) {
2599
2509
  if (inPlace) {
@@ -2618,10 +2528,14 @@ function createDOMPurify() {
2618
2528
  if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) returnNode = importNode.call(originalDocument, returnNode, true);
2619
2529
  return returnNode;
2620
2530
  }
2621
- let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2531
+ const serialize = () => WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
2532
+ let serializedHTML = serialize();
2533
+ if (SAFE_FOR_TEMPLATES && regExpTest(TMPL_MARKER_SERIALIZED, serializedHTML)) {
2534
+ _scrubOwnCharacterData(body);
2535
+ serializedHTML = serialize();
2536
+ }
2622
2537
  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;
2623
- if (SAFE_FOR_TEMPLATES) serializedHTML = _stripTemplateExpressions(serializedHTML);
2624
- return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
2538
+ return _signOutput(serializedHTML);
2625
2539
  };
2626
2540
  DOMPurify.setConfig = function() {
2627
2541
  let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};