Repository navigation
Fix duplicate glob results when ignoring case - #247
Merged
facelessuser merged 1 commit intoOct 19, 2026
Merged
Conversation
With IGNORECASE, `glob.glob(['A*', '*b'], flags=glob.IGNORECASE)` returned a file named `Ab` twice, although `glob` and `iglob` return only unique paths unless NOUNIQUE is set. Case is ignored by default on Windows, too. The unique check looked up the lower case path, but the set stored the path as is, so a path with an upper case letter never found its own entry. Look up and store one key instead. The key is the lower case path only when the file system ignores case, so files that differ only by case on a case sensitive file system are both returned when case is ignored. Before, one of them could be dropped depending on the order they were listed.
Owner
|
@gir-bot lgtm |
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.
glob.glob(['A*', '*b'], flags=glob.IGNORECASE)returns a file namedAbtwice, and so doesiglob. The docs sayglobandiglobreturn only unique paths unlessNOUNIQUEis set, so the result should be['Ab']. Windows ignores case by default, so it should hit this without the flag; I only ran it withIGNORECASE. The latest release, 11.1, returns the path twice, as does every release from 8.1.1. 8.0, 8.0.1 and 8.1 return it once._is_uniquelooks up the lower case path but stores the path as is, so a path with an upper case letter never finds its own entry. The 8.1.1 fix for #164 corrected the lookup and left the store as it was.It now looks up and stores one key: the lower case path when the file system ignores case, and the path as is otherwise. The file system decides, not
IGNORECASE, becauseaandAare two files on a case sensitive file system, and #164 was a report of one of them being dropped. This changes one result there: withIGNORECASE,glob.glob('*')could drop one of the two depending on the order the file system lists them, and now returns both.I added one row to
Testglob.cases:{E*,*F}withIGNORECASEexpects only the existing fixture fileEF.TestGlobMarkedandTestGlobCornerCaseMarkedreuse the table, and without the fix the row fails in all three.TestCase.test_case_uniquechecks thataandAare both returned withIGNORECASE, for*and for['a*', 'A*']; without the fix its result depends on the listing order, and it skips itself when the file system cannot hold both names, astest_casedoes. The full suite passes with the fix. There is a changelog line under 11.2.