From 51d165a8e71ca84112708af4a9add7a71e4ee424 Mon Sep 17 00:00:00 2001 From: Tranquil-Flow Date: Sat, 30 May 2026 03:15:30 +0200 Subject: [PATCH] fix(gateway): support Windows absolute paths in MEDIA tag regex and extract_local_files (#34632) The MEDIA_TAG_CLEANUP_RE and extract_local_files path regex both used (?:~/|/) to anchor paths, which only matches Unix-style absolute and home-relative paths. Two additional _TOOL_MEDIA_RE patterns in run.py had the same limitation. Windows absolute paths (C:\Users\..., D:/...) were silently ignored, causing MEDIA directive delivery to fail. Add [A-Za-z]:[/\\] as a third anchor alternative in all four regex locations (base.py x2, run.py x2). Also update path separators in extract_local_files from / to [/\\] so it can traverse Windows directory trees. Revert accidental + quantifier in MEDIA_TAG_CLEANUP_RE lookahead that changed match-one to match-one-or-more (unrelated to fix). Fixes: #34632 --- gateway/platforms/base.py | 9 +- gateway/run.py | 4 +- tests/gateway/test_platform_base.py | 39 +++++++ tests/gateway/test_run_tool_media_re.py | 147 ++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 tests/gateway/test_run_tool_media_re.py diff --git a/gateway/platforms/base.py b/gateway/platforms/base.py index 6979a869148..e1b677f12a1 100644 --- a/gateway/platforms/base.py +++ b/gateway/platforms/base.py @@ -1191,10 +1191,12 @@ _MEDIA_EXT_ALTERNATION = "|".join( # bare-path detector (extract_local_files) downstream rather than silently # deleted. Shared by the non-streaming dispatch path and the streaming # consumer so both behave identically. +# Path anchors: ``~/`` (Unix home-relative), ``/`` (Unix absolute), +# ``X:\\`` or ``X:/`` (Windows drive-letter absolute — #34632). MEDIA_TAG_CLEANUP_RE = re.compile( r'''[`"']?MEDIA:\s*''' r'''(?P`[^`\n]+`|"[^"\n]+"|'[^'\n]+'|''' - r'''(?:~/|/)\S+(?:[^\S\n]+\S+)*?\.(?:''' + _MEDIA_EXT_ALTERNATION + r'''))''' + r'''(?:~/|/|[A-Za-z]:[/\\])\S+(?:[^\S\n]+\S+)*?\.(?:''' + _MEDIA_EXT_ALTERNATION + r'''))''' r'''(?=[\s`"',;:)\]}]|$)[`"']?''', re.IGNORECASE, ) @@ -2665,9 +2667,10 @@ class BasePlatformAdapter(ABC): # (?