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