fix: strip anchored glob patterns on Windows to avoid NotImplementedError - #5682
Open
icn5381 wants to merge 1 commit into
Open
fix: strip anchored glob patterns on Windows to avoid NotImplementedError#5682icn5381 wants to merge 1 commit into
icn5381 wants to merge 1 commit into
Conversation
…rror On Windows, a pattern starting with / is not absolute per os.path.isabs() (no drive letter), but pathlib.Path.glob() treats it as an anchored pattern and raises NotImplementedError. This crashed /add and /read-only when the user passed a forward-slash path on Windows. Add _safe_glob_pattern() to strip the leading slash on Windows (it is a no-op on POSIX), apply it at both Path.glob() call sites in commands.py, and add NotImplementedError to the exception handler in glob_filtered_to_repo as a belt-and-braces fallback. Fixes Aider-AI#5679 Fixes Aider-AI#5675
|
|
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.
Issue
Fixes #5679
Fixes #5675
On Windows, a pattern starting with
/is not absolute peros.path.isabs()(no drive letter), butpathlib.Path.glob()treats it as an "anchored" pattern and raisesNotImplementedError: Non-relative patterns are unsupported. This crashes/addand/read-onlywhen the user passes a forward-slash path like/add /some/file.py.Fix
_safe_glob_pattern()helper: on Windows (os.name == "nt"), strips the leading/from a pattern soPath.glob()treats it as relative to the glob root (which is what the user intended). No-op on POSIX.Path.glob()call sites incommands.py(glob_filtered_to_repo~line 774, read-only file collection ~line 1361).NotImplementedErrorto the existing exception handler inglob_filtered_to_repoas a fallback for any other anchored-pattern shapes.Testing
4 new unit tests in
TestSafeGlobPatterncover:/foo/bar→foo/bar*.py,src/file.py)C:/drive/file.py)Note: the full test suite could not be run locally because Python 3.14 removed
audioop, whichpydub(an aider dependency) requires. The helper function logic was verified independently with mockedos.nameon both platforms.