Skip to content

🐍 refactor: Normalize Non-Standard Browser MIME Type Aliases in inferMimeType#12240

Merged
danny-avila merged 4 commits into
devfrom
fix/python-mime-type-validation
Mar 15, 2026
Merged

🐍 refactor: Normalize Non-Standard Browser MIME Type Aliases in inferMimeType#12240
danny-avila merged 4 commits into
devfrom
fix/python-mime-type-validation

Conversation

@danny-avila

@danny-avila danny-avila commented Mar 15, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes Python file uploads being rejected on macOS, where Chrome and Firefox report .py files as text/x-python-script instead of the canonical text/x-python, causing client-side MIME validation to fail.

  • Introduces a mimeTypeAliases constant (Readonly<Record<string, string>>) in file-config.ts that maps known non-standard browser-reported MIME types to their canonical equivalents.
  • Extends inferMimeType to 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.
  • Restores and improves the inferMimeType JSDoc with @param and @returns annotations, including documenting the empty-string return case.
  • Adds two checkType integration tests that assert the before/after validation boundary directly: the raw text/x-python-script is rejected without normalization, and the normalized text/x-python is accepted.
  • Removes three redundant inferMimeType unit tests from DragDropModal.spec.tsx that duplicated coverage already present in file-config.spec.ts.
  • Corrects import sort order in file-config.spec.ts to longest-to-shortest per project conventions.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

Ran the full packages/data-provider test suite. The two new integration tests explicitly cover the broken state (raw text/x-python-script fails checkType) and the fixed state (normalized text/x-python passes checkType).

To reproduce the original bug manually: on macOS, open Chrome or Firefox, navigate to the chat input, and attempt to attach a .py file. Without this fix, the upload is rejected with an unsupported file type error. With this fix, the file is accepted and uploaded as text/x-python.

Test Configuration:

  • macOS (Chrome or Firefox) to reproduce the original browser MIME type behavior
  • cd packages/data-provider && npx jest inferMimeType to run the targeted unit and integration tests

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

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.
Copilot AI review requested due to automatic review settings March 15, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mimeTypeAliases map and applied it inside inferMimeType when a browser-provided MIME type is present.
  • Added unit tests in packages/data-provider for 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.

@danny-avila danny-avila changed the title fix/python mime type validation 🐍 refactor: Normalize Non-Standard Browser MIME Type Aliases in inferMimeType Mar 15, 2026
@danny-avila danny-avila merged commit 7c39a45 into dev Mar 15, 2026
11 checks passed
@danny-avila danny-avila deleted the fix/python-mime-type-validation branch March 15, 2026 02:43
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
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