From 9d6148316c5650c09d67fc7b06d9a8fda03c50bf Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Mon, 23 Mar 2026 06:59:59 -0700 Subject: [PATCH] fix: media delivery fails for file paths containing spaces (#2621) Cherry-picked from PR #2583 by Glucksberg. The MEDIA: regex used \S+ which truncated paths at the first space. Added a space-aware alternative anchored to known media extensions. Also updated extract_local_files to allow spaces in path segments. Follow-up fix: changed \s to [^\S\n] in the space-matching group so the regex doesn't greedily match across newlines (broke multi-line MEDIA: tags). --- gateway/platforms/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index 34c174b7..a1c21c75 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -721,7 +721,7 @@ class BasePlatformAdapter(ABC): # Extract MEDIA: tags, allowing optional whitespace after the colon # and quoted/backticked paths for LLM-formatted outputs. media_pattern = re.compile( - r'''[`"']?MEDIA:\s*(?P`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|\S+)[`"']?''' + r'''[`"']?MEDIA:\s*(?P`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:png|jpe?g|gif|webp|mp4|mov|avi|mkv|webm|ogg|opus|mp3|wav|m4a)(?=[\s`"',;:)\]}]|$)|\S+)[`"']?''' ) for match in media_pattern.finditer(content): path = match.group("path").strip()