Skip to content

[Bug]: MEDIA: tags with Windows paths not parsed — images sent as plain text #28989

@Daevalus

Description

@Daevalus

[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

  • 🐛 Bug fix

Files Changed

  • gateway/platforms/base.py — 1 line changed in regex pattern

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions