fix(memory): match clear_pattern case-sensitively on every platform - #204
Merged
Merged
Conversation
fnmatch.fnmatch runs both arguments through os.path.normcase, which lowercases on Windows, so cache:user:* also cleared cache:User:1 there. Redis matches case-sensitively everywhere. Use fnmatch.fnmatchcase. Document the two places where the memory glob syntax still differs from Redis: [!...] negation and bracket escapes instead of backslashes. Closes #179
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.
Closes #179
Summary
MemoryBackend.clear_pattern()now usesfnmatch.fnmatchcase.fnmatch.fnmatchpasses both arguments throughos.path.normcase, which lowercases on Windows, socache:user:*also clearedcache:User:1there. Redis is case-sensitive everywhere.docs/BACKENDS.md(and zh-TW) where the memory glob syntax still differs from Redis.Glob differences, checked against a live Redis
a[*]ba*ba*ba\*ba\b(backslash is literal)a*ba[!x]bxa!b,axba[^x]ba^b,axbxa?bSo the docs recommend bracket escapes, and note that negation is
[!...]on memory and[^...]on Redis. Making memory accept Redis syntax would change the meaning of existing patterns, so it is left out of this fix.Tests
test_memory_backend_clear_pattern_is_case_sensitive_on_windowsswapsos.path.normcaseforntpath.normcase. With the fix stashed, it is the only test that fails.mypy --strict, and the full suite against live Redis and Memcached (CACHEX_REQUIRE_LIVE_SERVERS=1): 858 passed.