Skip to content
Open
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 @@ -2064,7 +2064,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]+'|(?:~/|/|[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|kmz|kml|geojson|gpx|json|xml|html?)(?=[\s`"',;:)\]}]|$)|\S+)[`"']?'''

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds drive-letter matching but does not match the UNC paths described in the PR body: \\server\share\file.pdf has no [A-Za-z]: prefix. Either remove the UNC claim or add dedicated support and regression coverage.

)
for match in media_pattern.finditer(content):
path = match.group("path").strip()
Expand Down
63 changes: 63 additions & 0 deletions tests/gateway/test_platform_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,69 @@ def test_both_directives_can_coexist(self):
assert "[[audio_as_voice]]" not in cleaned
assert "[[as_document]]" not in cleaned

def test_windows_drive_letter_path_with_spaces(self):
"""Windows drive-letter paths with spaces should not be truncated."""
content = "MEDIA:C:\\Users\\Confera\\OneDrive\\My Folder\\report.pdf"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "C:\\Users\\Confera\\OneDrive\\My Folder\\report.pdf"
assert cleaned == ""

def test_windows_drive_letter_path_no_spaces(self):
"""Windows drive-letter paths without spaces should still work."""
content = "MEDIA:C:\\Users\\test\\file.png"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert "C:\\Users\\test\\file.png" == media[0][0]

def test_gis_extension_kmz(self):
"""GIS .kmz extension should be recognized in spaced paths."""
content = "MEDIA:/home/user/My Folder/coords.kmz"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/home/user/My Folder/coords.kmz"

def test_gis_extension_geojson(self):
"""GIS .geojson extension should be recognized."""
content = "MEDIA:/data/map.geojson"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/data/map.geojson"

def test_gis_extension_gpx(self):
"""GIS .gpx extension should be recognized."""
content = "MEDIA:/data/track.gpx"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/data/track.gpx"

def test_json_extension(self):
"""JSON extension should be recognized."""
content = "MEDIA:/tmp/data.json"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/tmp/data.json"

def test_xml_extension(self):
"""XML extension should be recognized."""
content = "MEDIA:/tmp/data.xml"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/tmp/data.xml"

def test_html_extension(self):
"""HTML extension should be recognized."""
content = "MEDIA:/tmp/page.html"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "/tmp/page.html"

def test_windows_spaced_path_with_gis_extension(self):
"""Windows spaced path with GIS extension should work end-to-end."""
content = "MEDIA:C:\\Users\\Foo\\OneDrive\\My Folder\\coords.kmz"
media, cleaned = BasePlatformAdapter.extract_media(content)
assert len(media) == 1
assert media[0][0] == "C:\\Users\\Foo\\OneDrive\\My Folder\\coords.kmz"

# ---------------------------------------------------------------------------
# should_send_media_as_audio
Expand Down
Loading