fix(gateway): support Windows drive-letter paths in MEDIA: tags and extract_local_files#30778
fix(gateway): support Windows drive-letter paths in MEDIA: tags and extract_local_files#30778fanyi-zhao wants to merge 1 commit into
Conversation
…tract_local_files On Windows, MEDIA:D:\path\to\file.png tags and bare local file paths (D:\dev\...\screen.png) were not detected because the regex patterns only matched Unix-style paths (/abs/path or ~/home/path). Changes: - extract_media: add [A-Za-z]:[\\/] for Windows drive-letter prefix - extract_local_files: add drive-letter prefix + [\\/] path separator - run.py _TOOL_MEDIA_RE: add drive-letter prefix (×2 occurrences) Tests added: - test_extract_local_files: Windows backslash, forward slash, bare drive, UNC path, text cleanup - test_media_extraction: Windows path extraction, Unix path preservation, HTTP URL rejection Safety: all paths validated with os.path.exists()/isfile(); no Linux regression — [\\/] matches both \ and /.
66e4109 to
412157c
Compare
|
Note: this PR enters a crowded space with several competing fixes for the same Windows drive-letter MEDIA: path bug (#28989, #24032):
Maintainers should pick one and close the rest to avoid merge conflicts. |
@alt-glitch Thanks for surfacing the full landscape — really helpful context. I agree maintainers should consolidate. Here's how the three active PRs compare:
#30778 is the only one that covers both entry points in a single, minimal change (each regex just gains a If instead the plan is to merge #24049 + #28991, I think #24049 has two concerns worth flagging:
Suggestion: merge #30778 as the canonical fix, close #24049 and #28991. The spaced-path support and any extension additions can be evaluated as standalone follow-ups. |
|
@teknium1 @OutThisLife @alt-glitch Could you please review this pull request when you get a chance? Your expertise in this area would be greatly appreciated. Thank you! |
What does this PR do?
Fixes Windows drive-letter path support for
MEDIA:tags andextract_local_files.On Windows, paths like
MEDIA:D:\path\to\file.pngand bare paths likeD:\dev\...\screen.pngwere silently ignored because the regex patterns only matched Unix-style paths (/abs/pathor~/home/path).Related Issue
N/A (no existing issue — discovered during Discord file attachment testing on Windows)
Type of Change
Changes Made
gateway/platforms/base.py—extract_media():(?:~/|/)→(?:[A-Za-z]:[\\/]|~/|/)gateway/platforms/base.py—extract_local_files(): prefix +/→[\\/]path separatorgateway/run.py—_TOOL_MEDIA_RE(×2):(?:/|~\/)→(?:[A-Za-z]:[\\/]|/|~\/)tests/gateway/test_extract_local_files.py— 5 new Windows path teststests/gateway/test_media_extraction.py— 6 new Windows/Unix/URL testsHow to Test
MEDIA:D:\path\to\image.pngvia send_messageD:\dev\...\file.pdfare detected in responsespytest tests/gateway/test_extract_local_files.py tests/gateway/test_media_extraction.pyChecklist
Code
Documentation & Housekeeping