From c647668aba51e503274b56ebdfe145bf59c763d6 Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Wed, 12 Aug 2026 03:17:26 +0800 Subject: [PATCH] fix(paste): respect tool sanitize config for paste tags (Fixes #2984) --- src/components/modules/paste.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/modules/paste.ts b/src/components/modules/paste.ts index 6a8378c41..d0e03efb0 100644 --- a/src/components/modules/paste.ts +++ b/src/components/modules/paste.ts @@ -204,11 +204,26 @@ export default class Paste extends Module { /** Add all tags that can be substituted to sanitizer configuration */ const toolsTags = Object.keys(this.toolsTags).reduce((result, tag) => { + const tagLowerCase = tag.toLowerCase(); + /** * If Tool explicitly specifies sanitizer configuration for the tag, use it. - * Otherwise, remove all attributes + * Otherwise, check if the tool's sanitize config has rules for this tag. + * If not, remove all attributes. */ - result[tag.toLowerCase()] = this.toolsTags[tag].sanitizationConfig ?? {}; + const sanitizationConfig = this.toolsTags[tag].sanitizationConfig; + + if (sanitizationConfig !== null) { + result[tagLowerCase] = sanitizationConfig; + } else { + const toolSanitizeConfig = this.toolsTags[tag].tool.sanitizeConfig as SanitizerConfig; + + if (toolSanitizeConfig[tagLowerCase]) { + result[tagLowerCase] = toolSanitizeConfig[tagLowerCase]; + } else { + result[tagLowerCase] = {}; + } + } return result; }, {}); @@ -656,15 +671,16 @@ export default class Paste extends Module { const tags = this.collectTagNames(tagOrSanitizeConfig); tags.forEach((tag) => { + const tagLowerCase = tag.toLowerCase(); const sanitizationConfig = _.isObject(tagOrSanitizeConfig) ? tagOrSanitizeConfig[tag] : null; - result[tag.toLowerCase()] = sanitizationConfig || {}; + result[tagLowerCase] = sanitizationConfig ?? tool.sanitizeConfig[tagLowerCase] ?? {}; }); return result; }, {}); - const customConfig = Object.assign({}, toolTags, tool.baseSanitizeConfig); + const customConfig = Object.assign({}, toolTags, tool.sanitizeConfig); /** * A workaround for the HTMLJanitor bug with Tables (incorrect sanitizing of table.innerHTML)