Skip to content

fix(frontend): handlePaste deduplication and MIME extension sanitization#211

Open
smeinecke wants to merge 2 commits into
cupcakearmy:mainfrom
smeinecke:fix-208-fwa-wup
Open

fix(frontend): handlePaste deduplication and MIME extension sanitization#211
smeinecke wants to merge 2 commits into
cupcakearmy:mainfrom
smeinecke:fix-208-fwa-wup

Conversation

@smeinecke

Copy link
Copy Markdown
Contributor

As I checked #208, I found some other bugs I introduced.

Bug 1: handlePaste double-adds pasted files

In handlePaste, the code first pushes all entries from data.files into raw[], then iterates data.items and pushes every kind === 'file' item — but per spec these represent the same files. The name|size dedup on line 86 hides this in most cases, but two intentionally identical files get silently merged into one.

Fix: iterate only data.items (filtering kind === 'file') and skip the data.files loop entirely.

Bug 2: MIME subtype used verbatim as file extension

const ext = file.name.includes('.') ? '' : `.${file.type.split('/')[1] || 'bin'}`

For image/svg+xml this produces .svg+xml, and for .docx it produces .vnd.openxmlformats-officedocument.... Recipients download files with broken extensions.

Fix: add a mimeToExt() helper with a lookup map for compound MIME types (image/svg+xmlsvg, etc.) and strip +suffix from the subtype fallback.

smeinecke and others added 2 commits June 16, 2026 18:08
- Remove data.files loop to prevent double-adding pasted files.
  The DataTransfer.items iteration already covers all files.
- Add mimeToExt() helper: lookup map for common compound MIME types
  (e.g. image/svg+xml -> svg) and strip +suffix from subtype fallback.
  Fixes invalid extensions like .svg+xml or .vnd.openxmlformats...
@cupcakearmy

Copy link
Copy Markdown
Owner

Thanks for the mime stuff!

I would like to use the mime package and not maintain a custom list :)

mime.getExtension('application/json');         // ⇨ 'json'

Regarding the duplication: i see where this is coming from, but cannot reproduce in ff and/or chrome. How can I repro?

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.

2 participants