Skip to content

fix(file): match extension accept specifiers by filename#4184

Merged
Kiarokh merged 1 commit into
mainfrom
fix/file-accept-extension-matching
Jul 14, 2026
Merged

fix(file): match extension accept specifiers by filename#4184
Kiarokh merged 1 commit into
mainfrom
fix/file-accept-extension-matching

Conversation

@Kiarokh

@Kiarokh Kiarokh commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

What

fix #4183
limel-file-dropzone filters dropped files with isTypeAccepted (src/util/files.ts). For a .ext accept specifier it matched against the file's MIME subtype (contentType.endsWith('/ext')), not the filename:

if (acceptedType.startsWith('.')) {
    const fileType = acceptedType.split('.')[1]; // ".docx" -> "docx"
    return file.contentType.endsWith(`/${fileType}`);
}

That only works when the subtype happens to equal the extension (.pdfapplication/pdf, .csvtext/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 matches accept by filename. split('.')[1] also meant multi-part extensions like .tar.gz never matched.

Change

Match .ext specifiers against the filename (case-insensitively), the way the native accept attribute does. MIME specifiers (type/subtype and type/*) still match contentType and are unchanged.

Tests

src/util/files.spec.ts: the existing describe.each files now carry a filename (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-file only wires the dropzone's filesSelected, not filesRejected, 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

  • Bug Fixes
    • Improved file type validation for extension-based accept rules.
    • Added support for case-insensitive filename matching, multi-part extensions, and comma-separated accept lists.
    • Fixed handling of document extensions such as .docx.
    • Improved validation when the content type is unavailable or unreliable.

`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>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

isTypeAccepted now matches extension-based accept specifiers against the filename, including case-insensitive and multipart suffixes. Tests update existing cases with filenames and add regression coverage for mismatches, unhelpful MIME types, and accept lists.

Changes

Filename extension acceptance

Layer / File(s) Summary
Filename matching and regression coverage
src/util/files.ts, src/util/files.spec.ts
Extension specifiers are checked against file.filename using a case-insensitive suffix comparison. Tests cover matching, mismatches, .docx, multipart extensions, case differences, unhelpful content types, and comma-separated accept lists.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 4183: The change addresses its filename-based extension matching objective in isTypeAccepted.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: matching extension accept specifiers by filename.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/file-accept-extension-matching

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4184/

@Kiarokh Kiarokh enabled auto-merge (rebase) July 13, 2026 13:28
@Kiarokh Kiarokh merged commit b59f4ec into main Jul 14, 2026
32 of 34 checks passed
@Kiarokh Kiarokh deleted the fix/file-accept-extension-matching branch July 14, 2026 08:36
@lime-opensource

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 39.44.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

limel-file: extension-based accept specifiers reject valid files on drag-and-drop

3 participants