Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gateway/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ def extract_media(content: str) -> Tuple[List[Tuple[str, bool]], str]:
# Extract MEDIA:<path> tags, allowing optional whitespace after the colon
# and quoted/backticked paths for LLM-formatted outputs.
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`"',;:)\]}]|$)|\S+)[`"']?'''
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`"',;:)\]}]|$)|(?:~/|/)\S+)[`"']?'''
)
for match in media_pattern.finditer(content):
path = match.group("path").strip()
Expand Down
10 changes: 10 additions & 0 deletions tests/gateway/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@ def test_extract_media_finds_image_tag(self):
assert media[0][0] == "/tmp/price_graph.png"
assert "MEDIA:" not in cleaned

def test_extract_media_ignores_relative_word_fallback(self):
"""extract_media() must not capture plain words or relative tokens after MEDIA:."""
from gateway.platforms.base import BasePlatformAdapter
media, _ = BasePlatformAdapter.extract_media("MEDIA:description")
assert media == [], "plain word after MEDIA: must not be extracted"
media2, _ = BasePlatformAdapter.extract_media("MEDIA:relative/path.png")
assert media2 == [], "relative path without leading slash must not be extracted"
media3, _ = BasePlatformAdapter.extract_media("MEDIA:/tmp/file.ogg")
assert len(media3) == 1 and media3[0][0] == "/tmp/file.ogg"

def test_extract_media_finds_audio_tag(self):
"""BasePlatformAdapter.extract_media should find MEDIA: audio paths."""
from gateway.platforms.base import BasePlatformAdapter
Expand Down
Loading