[Bug]: MEDIA: tags with Windows paths are not parsed, causing images to be sent as plain text
Summary
The extract_media() function in gateway/platforms/base.py uses a regex that only matches Unix-style paths (~/ or /). Windows paths like C:/Users/.../image.jpg or C:\\Users\\...\\image.jpg are not recognized, so MEDIA: tags are not extracted and the raw path text is sent to messaging platforms instead of the actual image.
This is a root cause of issue #6249 and related media delivery failures on Windows.
Environment
- OS: Windows 10/11
- Hermes version: 0.14.0
- Affected platforms: All messaging platforms (Telegram, Discord, Slack, etc.)
Root Cause
In gateway/platforms/base.py, line ~2162:
media_pattern = re.compile(
r'''[`"']?MEDIA:\s*(?P<path>`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?'''
)
The path matching group (?:~/|/) only matches:
~/ (Unix home directory)
/ (Unix absolute path)
It does NOT match:
C:/ or C:\\ (Windows drive letters)
D:/, E:/, etc.
Reproduction
On Windows, call send_message with a Windows path:
send_message_tool({
"action": "send",
"target": "telegram:CHAT_ID",
"message": "MEDIA:C:/Users/gizmo/image.jpg"
})
Expected: Image is uploaded as native attachment.
Actual: The text MEDIA:C:/Users/gizmo/image.jpg is sent as a plain message.
Fix
Change the path matching group from (?:~/|/) to (?:~/|/|[A-Za-z]:[/\\]):
media_pattern = re.compile(
r'''[`"']?MEDIA:\s*(?P<path>`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/|[A-Za-z]:[/\\])\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a|flac|epub|pdf|zip|rar|7z|docx?|xlsx?|pptx?|txt|csv|apk|ipa)(?=[\s`"',;:)\]}]|$))[`"']?'''
)
This adds support for Windows drive letters with both forward and backward slashes.
Related Issues
Type of Change
Files Changed
gateway/platforms/base.py — 1 line changed in regex pattern
[Bug]: MEDIA: tags with Windows paths are not parsed, causing images to be sent as plain text
Summary
The
extract_media()function ingateway/platforms/base.pyuses a regex that only matches Unix-style paths (~/or/). Windows paths likeC:/Users/.../image.jpgorC:\\Users\\...\\image.jpgare not recognized, soMEDIA:tags are not extracted and the raw path text is sent to messaging platforms instead of the actual image.This is a root cause of issue #6249 and related media delivery failures on Windows.
Environment
Root Cause
In
gateway/platforms/base.py, line ~2162:The path matching group
(?:~/|/)only matches:~/(Unix home directory)/(Unix absolute path)It does NOT match:
C:/orC:\\(Windows drive letters)D:/,E:/, etc.Reproduction
On Windows, call
send_messagewith a Windows path:Expected: Image is uploaded as native attachment.
Actual: The text
MEDIA:C:/Users/gizmo/image.jpgis sent as a plain message.Fix
Change the path matching group from
(?:~/|/)to(?:~/|/|[A-Za-z]:[/\\]):This adds support for Windows drive letters with both forward and backward slashes.
Related Issues
Type of Change
Files Changed
gateway/platforms/base.py— 1 line changed in regex pattern