@devries-cameron20 / composio Mirror · read-only / commits / f016bcebb
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 18:30 UTC

fix(mimetypes): make guess() case-insensitive on file extensions (#3899)

guess() in composio/utils/mimetypes.py looked up Path(file).suffix against the lowercase _types table without normalizing case, so uppercase suffixes like .PNG or .PDF resolved to application/octet-stream instead of the correct MIME type. Since guess() feeds the mimetype field on file uploads (core/models/_files.py), uploads from phone cameras, scanners and Windows — where uppercase extensions are common — were getting the wrong content type. The fix is a one-line normalization: Path(file).suffix.lower() before the table lookup. This aligns guess() with its sibling get_extension_from_mime_type, which is already case-insensitive, and with the stdlib mimetypes.guess_type. I updated the existing test that documented the old case-sensitive behavior to assert the case-insensitive result instead. Fixes #3857 <!-- codesmith:footer --> --- <a href="https://app.blacksmith.sh/ComposioHQ/codesmith/composio/pr/3899"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-light-v2.svg"><img alt="View with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"></picture></a> <a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1787222508&installation_model_id=428187&pr_number=3899&repository=ComposioHQ%2Fcomposio&return_to=https%3A%2F%2Fgithub.com%2FComposioHQ%2Fcomposio%2Fpull%2F3899&signature=51d4b1022aa69bc47f45a7daf2e704db96c5eb2a2f267141010ca769b502a062"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"></picture></a> <sup>Need help on this PR? Tag <code>/codesmith</code> with what you need. Autofix is disabled.</sup> <!-- codesmith:autofix:disabled --> <!-- /codesmith:footer --> Signed-off-by: sergioperezcheco <checo520@outlook.com> Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com> Co-authored-by: jkomyno <alberto@composio.dev>

Checo committed Jul 28, 2026 at 15:48 UTC f016bcebb99615bcf8f68f5a9e8488282e5b837e
2 files changed +7 -4
python/composio/utils/mimetypes.py
+1 -1
@@ -507,7 +507,7 @@ _types = {
507
508
509 def guess(file: t.Union[str, Path]) -> str:
510 - return _types.get(Path(file).suffix, _default)
510 + return _types.get(Path(file).suffix.lower(), _default)
511
512
513 # MIME type -> extension (no leading dot). Used when deriving filenames from
python/tests/test_mimetypes.py
+6 -3
@@ -33,9 +33,12 @@ class TestGuess:
33 """A known extension resolves to its MIME type."""
34 assert guess(filename) == expected
35
36 - def test_extension_lookup_is_case_sensitive(self) -> None:
37 - """The extension table is lower-case, so an upper-case suffix misses."""
38 - assert guess("photo.PNG") == _default
36 + def test_extension_lookup_is_case_insensitive(self) -> None:
37 + """Suffixes are normalized to lower case, matching the sibling
38 + ``get_extension_from_mime_type`` helper and ``mimetypes.guess_type``."""
39 + assert guess("photo.PNG") == "image/png"
40 + assert guess("report.PDF") == "application/pdf"
41 + assert guess("archive.ZIP") == "application/zip"
42
43 def test_unknown_extension_returns_default(self) -> None:
44 assert guess("file.unknownext") == _default