fix(gateway): match uppercase media extensions in MEDIA: pattern - #32695
Closed
InphinitiZ wants to merge 1 commit into
Closed
fix(gateway): match uppercase media extensions in MEDIA: pattern#32695InphinitiZ wants to merge 1 commit into
InphinitiZ wants to merge 1 commit into
Conversation
Collaborator
The MEDIA:<path> regex in extract_media hardcoded lowercase extensions (png, jpe?g, mp4, ...) with no re.IGNORECASE flag, so paths emitted by the agent with uppercase suffixes (e.g. MEDIA:/.../IMG_0001.JPG from a folder of camera-style filenames) silently leaked through as plain text instead of being delivered as media attachments. Add re.IGNORECASE to media_pattern only — the regex body itself is unchanged. extract_local_files already uses re.IGNORECASE on its bare-path matcher, so no change needed there.
InphinitiZ
force-pushed
the
fix/media-regex-ignorecase-v2
branch
from
May 26, 2026 16:17
015a9f0 to
6c61ab2
Compare
Author
|
Thanks @alt-glitch for the pointer — closing as duplicate of #30535 / #30722. Will track #30526 instead. |
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
The
MEDIA:<path>regex inBasePlatformAdapter.extract_media(gateway/platforms/base.py) hardcodes lowercase file extensions (png|jpe?g|gif|webp|mp4|...) and is compiled withoutre.IGNORECASE. As a result, any path the agent emits with an uppercase extension — common for camera-style filenames likeIMG_0001.JPG— silently bypasses the MEDIA extraction path and gets shipped to the user as plain text instead of being delivered as a native media attachment.In practice this affects anyone whose media library was sourced from a smartphone or DSLR (which routinely produce
.JPG/.MP4/.MOV), or whose OS / file picker preserves uppercase suffixes.Reproduction
Before this fix:
End-to-end symptom: the user receives the literal string
MEDIA:/photos/IMG_0001.JPGin their chat instead of the photo.Fix
Add
re.IGNORECASEtomedia_pattern. The regex body itself is unchanged.extract_local_files's bare-path matcher already usesre.IGNORECASE, so no change is needed there — only the explicitMEDIA:tag path was affected.Tests
Adds two regression tests to
tests/gateway/test_platform_base.py:test_extract_media_uppercase_jpg_extension— single uppercase extension (IMG_0001.JPG).test_extract_media_mixed_case_extensions—.PNG,.JPG,.Jpeg,.MP4mixed in one response.Both fail without the flag and pass with it.
Relationship to #29620
PR #29620 also incidentally adds
re.IGNORECASE(alongside a character-class reorder). Its stated motivation — that\]inside the lookahead character class prematurely terminates the class — does not actually reproduce; the original character class compiles and matchesMEDIA:/tmp/test.png)/]/}correctly. The real bug being fixed there is the missingre.IGNORECASE, which is what this PR isolates with a minimal diff and dedicated regression tests. Happy to defer to #29620 if reviewers prefer that branch.