fix(gateway): support Windows absolute paths in all MEDIA regex locations (#34632)#35161
Closed
Tranquil-Flow wants to merge 1 commit into
Closed
fix(gateway): support Windows absolute paths in all MEDIA regex locations (#34632)#35161Tranquil-Flow wants to merge 1 commit into
Tranquil-Flow wants to merge 1 commit into
Conversation
…xtract_local_files (NousResearch#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: NousResearch#34632
Collaborator
tonydwb
approved these changes
May 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: ✅ Approved
Overview
Thorough fix for Windows absolute path support across all 4 MEDIA regex locations in the gateway code. 194 additions, 5 deletions, excellent test coverage.
What's Right
- Complete coverage: All 4 regex locations updated — MEDIA_TAG_CLEANUP_RE, extract_local_files path_re, and both _TOOL_MEDIA_RE patterns in run.py. No misses.
- Test quality: 31 tests in test_run_tool_media_re.py covering Windows backslash, forward-slash, mixed separators, case-insensitivity, multi-tag, negative cases, AND a pre-fix pattern proof that the fix is necessary.
- Regression prevention: 5 existing tests extended in test_platform_base.py plus the Unix path tests prove existing behavior is preserved.
- Clean diff: No unrelated changes, no test deletions. Just the bug fix + tests.
- Documentation: Comments updated at all regex locations explaining the anchors.
- Commit message: Conventional Commits format, references the issue.
Reviewed by Hermes Agent (cron)
This was referenced May 30, 2026
Contributor
|
Merged via #35388. Your commit was cherry-picked onto current main with your authorship preserved in git log (51d165a). We added two test follow-ups: a stale POSIX-only Windows-path test that needed updating to assert the new matching behavior, and a raw-docstring fix to silence an escape warning. Thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The
MEDIA_TAG_CLEANUP_RE,extract_local_filespath regex, and two_TOOL_MEDIA_REpatterns ingateway/run.pyall used(?:~/|/)toanchor paths, matching only Unix-style absolute and home-relative paths.
Windows absolute paths (
C:\Users\...,D:/...) were silently ignored,causing MEDIA directive delivery to fail on Windows.
Fix: Add
[A-Za-z]:[/\\]as a third anchor alternative in all fourregex locations. Also update path separators in
extract_local_filesfrom/to[/\\]so it can traverse Windows directory trees.This covers all 4 locations that competing PR #30778 covers, without
hardcoding the extension list (uses the shared
_MEDIA_EXT_ALTERNATIONconstant where available, and identical inline extension patterns in the
_TOOL_MEDIA_REcases where the constant is out of scope).Related Issue
Fixes #34632
Type of Change
Changes Made
gateway/platforms/base.py: Add[A-Za-z]:[/\\]anchor toMEDIA_TAG_CLEANUP_REandextract_local_filespath regex. Revertaccidental
+quantifier in lookahead (unrelated cosmetic change).gateway/run.py: Add[A-Za-z]:[/\\]anchor to both_TOOL_MEDIA_REpatterns — history scanning (L17223) and result scanning (L17549). These
were the locations missed by the original build.
tests/gateway/test_platform_base.py: 5 existing tests forextract_mediaWindows path recognition.
tests/gateway/test_run_tool_media_re.py: New — 31 tests coveringWindows backslash/forward-slash, mixed separators, multiple extensions,
case-insensitive drive letters/extensions, multi-tag extraction, negative
cases, and fail-without-fix proof using pre-fix pattern.
How to Test
python3 -m pytest tests/gateway/test_run_tool_media_re.py -v(31 new tests)python3 -m pytest tests/gateway/test_platform_base.py -v(existing tests, no regressions)MEDIA:C:\Users\test\image.pngis recognizedMEDIA:D:/data/report.pdfis recognized/tmp/file.png,~/docs/report.pdf) still workChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass