Skip to content

Fix duplicate glob results when ignoring case - #247

Merged
facelessuser merged 1 commit into
facelessuser:mainfrom
spicysharkco:fix/glob-unique-ignorecase
Oct 19, 2026
Merged

facelessuser merged 1 commit into
facelessuser:mainfrom
spicysharkco:fix/glob-unique-ignorecase

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

glob.glob(['A*', '*b'], flags=glob.IGNORECASE) returns a file named Ab twice, and so does iglob. The docs say glob and iglob return only unique paths unless NOUNIQUE is set, so the result should be ['Ab']. Windows ignores case by default, so it should hit this without the flag; I only ran it with IGNORECASE. 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_unique looks 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, because a and A are two files on a case sensitive file system, and #164 was a report of one of them being dropped. This changes one result there: with IGNORECASE, 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} with IGNORECASE expects only the existing fixture file EF. TestGlobMarked and TestGlobCornerCaseMarked reuse the table, and without the fix the row fails in all three. TestCase.test_case_unique checks that a and A are both returned with IGNORECASE, 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, as test_case does. The full suite passes with the fix. There is a changelog line under 11.2.

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.
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: docs Related to documentation. C: glob Glob library. C: source Related to source code. C: tests Related to testing. labels Oct 19, 2026
@facelessuser

Copy link
Copy Markdown
Owner

@gir-bot lgtm

@gir-bot gir-bot added S: approved The pull request is ready to be merged. and removed S: needs-review Needs to be reviewed and/or approved. labels Oct 19, 2026
@facelessuser
facelessuser merged commit 515345f into facelessuser:main Oct 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: docs Related to documentation. C: glob Glob library. C: source Related to source code. C: tests Related to testing. S: approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants