fix(file): match extension accept specifiers by filename#4184
Conversation
`isTypeAccepted` matched a `.ext` accept specifier against the file's
MIME subtype (`contentType.endsWith('/ext')`), which only works when the
subtype happens to equal the extension. Files whose subtype differs
(`.docx`, `.xlsx`, `.txt`, `.7z`, `.eml`, …) were silently rejected on
drag-and-drop, while the file chooser worked (the browser matches by
filename). Multi-part extensions like `.tar.gz` never matched either.
Match `.ext` specifiers against the filename, like the native `accept`
attribute. MIME specifiers (`type/subtype`, `type/*`) are unchanged.
Refs #4183
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesFilename extension acceptance
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4184/ |
|
🎉 This PR is included in version 39.44.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What
fix #4183
limel-file-dropzonefilters dropped files withisTypeAccepted(src/util/files.ts). For a.extaccept specifier it matched against the file's MIME subtype (contentType.endsWith('/ext')), not the filename:That only works when the subtype happens to equal the extension (
.pdf→application/pdf,.csv→text/csv). Files whose subtype differs were silently rejected on drag-and-drop — e.g. all Office/iWork/OpenDocument formats,.txt(text/plain),.eml/.msg, and most archives (.7z,.rar,.tar,.gz, …). The file chooser was unaffected, because the browser matchesacceptby filename.split('.')[1]also meant multi-part extensions like.tar.gznever matched.Change
Match
.extspecifiers against the filename (case-insensitively), the way the nativeacceptattribute does. MIME specifiers (type/subtypeandtype/*) still matchcontentTypeand are unchanged.Tests
src/util/files.spec.ts: the existingdescribe.eachfiles now carry afilename(which keeps every existing expectation valid), plus a new block covering the fix — an extension whose MIME subtype differs (.docx), multi-part extensions (.tar.gz), case-insensitivity, an unhelpful content type (application/octet-stream), and matching within a comma-separated list. All spec tests pass.Out of scope (follow-up)
limel-fileonly wires the dropzone'sfilesSelected, notfilesRejected, so a genuinely-unsupported dropped file is still silently ignored (no upload, no feedback). Surfacing that needs a small UX/API decision and is left as a follow-up — see the issue.Refs #4183
🤖 Generated with Claude Code
Summary by CodeRabbit
.docx.