Skip to content

fix(paste): respect tool sanitize config for paste tags (Fixes #2984) - #3019

Open
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/paste-sanitize-config-2984
Open

fix(paste): respect tool sanitize config for paste tags (Fixes #2984)#3019
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/paste-sanitize-config-2984

Conversation

@waterWang

Copy link
Copy Markdown

What does this PR do?

Fixes #2984pasteConfig ignores tool's sanitize rules.

Problem

When pasting HTML content, the paste module builds its sanitizer config only from the tool's pasteConfig.tags. When a tool declares its tags as plain strings (e.g. tags: ['P', 'DIV']), the sanitizationConfig for each tag is null, and the code falls back to {} — stripping all attributes from pasted elements.

Meanwhile the tool's static get sanitize() explicitly allows certain attributes (e.g. p: { style: true }). These rules are ignored during paste, so pasting from Google Docs loses paragraph indentation and other inline styles.

Fix

In Paste.processDataTransfer, when a tag has no explicit sanitization config from pasteConfig.tags, fall back to the tool's sanitizeConfig rules for that tag. Only if neither provides a rule do we strip all attributes.

Reproduction

class MyTool {
  static get pasteConfig() { return { tags: ['P', 'DIV'] }; }
  static get sanitize() { return { p: { style: true } }; }
  onPaste(event) { /* receives element */ }
}

Before: pasted <p style="text-indent: 36pt;"> becomes <p><span>...</span></p> (style stripped)
After: pasted <p style="text-indent: 36pt;"> is delivered to the tool with its style attribute preserved.

Checklist

  • Build passes (vite build)
  • No new type errors introduced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pasteConfig ignores tool's sanitize rules - style attributes stripped before onPaste receives element

1 participant