🐍 refactor: Normalize Non-Standard Browser MIME Type Aliases in inferMimeType#12240
Merged
Conversation
macOS Chrome/Firefox report .py files as text/x-python-script instead of text/x-python, causing client-side validation to reject Python file uploads. inferMimeType now normalizes known MIME type aliases before returning, so non-standard variants match the accepted regex patterns.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Python MIME type validation by normalizing a non-standard browser-reported MIME type (text/x-python-script) to the canonical text/x-python, ensuring it passes existing MIME regex checks and downstream validations.
Changes:
- Added a
mimeTypeAliasesmap and applied it insideinferMimeTypewhen a browser-provided MIME type is present. - Added unit tests in
packages/data-providerfor normalization and extension-based inference. - Added client-side test coverage to ensure UI-related MIME inference behavior is consistent.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/data-provider/src/file-config.ts | Introduces MIME alias normalization and applies it in inferMimeType. |
| packages/data-provider/src/file-config.spec.ts | Adds tests validating alias normalization and inference behavior. |
| client/src/components/Chat/Input/Files/tests/DragDropModal.spec.tsx | Adds client test coverage for the new alias normalization behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
inferMimeType
jcbartle
pushed a commit
to jcbartle/LibreChat
that referenced
this pull request
May 11, 2026
…rMimeType` (danny-avila#12240) * 🐛 fix: Normalize non-standard browser MIME types in inferMimeType macOS Chrome/Firefox report .py files as text/x-python-script instead of text/x-python, causing client-side validation to reject Python file uploads. inferMimeType now normalizes known MIME type aliases before returning, so non-standard variants match the accepted regex patterns. * 🧪 test: Add tests for MIME type alias normalization in inferMimeType * 🐛 fix: Restore JSDoc params and make mimeTypeAliases immutable * 🧪 test: Add checkType integration tests, remove redundant DragDropModal tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Python file uploads being rejected on macOS, where Chrome and Firefox report
.pyfiles astext/x-python-scriptinstead of the canonicaltext/x-python, causing client-side MIME validation to fail.mimeTypeAliasesconstant (Readonly<Record<string, string>>) infile-config.tsthat maps known non-standard browser-reported MIME types to their canonical equivalents.inferMimeTypeto apply alias normalization before returning when the browser provides a non-empty type, so the corrected type propagates through both client-side validation and the upload form payload.inferMimeTypeJSDoc with@paramand@returnsannotations, including documenting the empty-string return case.checkTypeintegration tests that assert the before/after validation boundary directly: the rawtext/x-python-scriptis rejected without normalization, and the normalizedtext/x-pythonis accepted.inferMimeTypeunit tests fromDragDropModal.spec.tsxthat duplicated coverage already present infile-config.spec.ts.file-config.spec.tsto longest-to-shortest per project conventions.Change Type
Testing
Ran the full
packages/data-providertest suite. The two new integration tests explicitly cover the broken state (rawtext/x-python-scriptfailscheckType) and the fixed state (normalizedtext/x-pythonpassescheckType).To reproduce the original bug manually: on macOS, open Chrome or Firefox, navigate to the chat input, and attempt to attach a
.pyfile. Without this fix, the upload is rejected with an unsupported file type error. With this fix, the file is accepted and uploaded astext/x-python.Test Configuration:
cd packages/data-provider && npx jest inferMimeTypeto run the targeted unit and integration testsChecklist