@devries-cameron20 / composio Mirror · read-only / commits / fc681b87b
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, 13:30 UTC

Fix .jpg resolving to non-standard image/jpg instead of image/jpeg (#4333)

## Problem `composio.utils.mimetypes.guess()` maps `.jpg` to `"image/jpg"`: ```python ".jpe": "image/jpeg", ".jpeg": "image/jpeg", ".jpg": "image/jpg", # <- non-standard ``` `image/jpg` is not a registered IANA media type. It is inconsistent with: - its own sibling extensions `.jpe`, `.jpeg`, and `.jfif-bnl`, which all map to `image/jpeg` - Python's standard library: `mimetypes.guess_type("x.jpg")` returns `image/jpeg` - IANA, which registers `image/jpeg` `guess()` feeds the `Content-Type` used for presigned uploads (`_upload_to_presigned_url`), so `.jpg` files are uploaded and stored with a non-standard content type. ## Fix Map `.jpg` to `image/jpeg`. One line. The reverse `_MIME_TO_EXT` map keeps its `"image/jpg": "jpg"` entry on purpose: the SDK should still accept `image/jpg` when a server sends it in a `Content-Type` header (liberal in what it accepts, strict in what it produces). ## Tests Added coverage in `tests/test_mimetypes.py`: `.jpg`/`.jpeg` in the known-extensions table plus a dedicated test documenting that `.jpg` resolves to `image/jpeg`. Verified the new tests fail on the old value and pass after the fix; the full `test_mimetypes.py` (35 tests) passes.

Swapnil Yadav committed Sep 3, 2026 at 15:57 UTC fc681b87b2e6a48527f17abb48c4517e48928477
2 files changed +13 -1
python/composio/utils/mimetypes.py
+1 -1
@@ -160,7 +160,7 @@ _types = {
160 ".jfif-bnl": "image/jpeg",
161 ".jpe": "image/jpeg",
162 ".jpeg": "image/jpeg",
163 - ".jpg": "image/jpg",
163 + ".jpg": "image/jpeg",
164 ".jps": "image/x-jps",
165 ".js": "application/javascript",
166 ".json": "application/json",
python/tests/test_mimetypes.py
+12
@@ -24,6 +24,8 @@ class TestGuess:
24 ("a.css", "text/css"),
25 ("a.js", "application/javascript"),
26 ("a.png", "image/png"),
27 + ("a.jpg", "image/jpeg"),
28 + ("a.jpeg", "image/jpeg"),
29 ("a.gif", "image/gif"),
30 ("a.mp4", "video/mp4"),
31 ("a.zip", "application/zip"),
@@ -33,6 +35,16 @@ class TestGuess:
35 """A known extension resolves to its MIME type."""
36 assert guess(filename) == expected
37
38 + def test_jpg_uses_the_standard_mime_type(self) -> None:
39 + """``.jpg`` resolves to the IANA-registered ``image/jpeg``, matching
40 + its ``.jpeg``/``.jpe`` siblings and ``mimetypes.guess_type`` in the
41 + standard library, rather than the non-standard ``image/jpg``. The
42 + reverse ``_MIME_TO_EXT`` map still accepts ``image/jpg`` from servers
43 + that send it."""
44 + assert guess("a.jpg") == "image/jpeg"
45 + assert guess("a.jpeg") == "image/jpeg"
46 + assert guess("a.jpe") == "image/jpeg"
47 +
48 def test_extension_lookup_is_case_insensitive(self) -> None:
49 """Suffixes are normalized to lower case, matching the sibling
50 ``get_extension_from_mime_type`` helper and ``mimetypes.guess_type``."""