fix: FileFilter must check exclude_dirs before the endswith shortcut#2989
Open
LeSingh1 wants to merge 1 commit into
Open
fix: FileFilter must check exclude_dirs before the endswith shortcut#2989LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
When an explicit path (no wildcards) is listed in --reload-include, FileFilter.__call__ hit the str(path).endswith(include_pattern) branch and returned True immediately, without checking whether the file lives inside a directory listed in --reload-exclude. The directory exclusion was therefore silently bypassed for any non-glob include pattern. Moving the exclude_dirs loop above the endswith shortcut preserves the original intent of that shortcut (allowing hidden/dotted files and other exact paths to bypass the *pattern* excludes) while still honouring directory-level exclusions for those same files.
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.
When an explicit path (e.g.
.dottedorext/ext.jpg) is listed in--reload-include,FileFilter.__call__matched viapath.match()and then hit the
str(path).endswith(include_pattern)shortcut, whichreturned
Trueimmediately. The early return skipped the loop thatchecks
exclude_dirs, so any file whose name exactly matched an includepattern was watched even when it lived inside a directory listed in
--reload-exclude.The
endswithshortcut was added in c55af77 to let hidden/dotted filesand other non-glob entries bypass the pattern-level excludes (e.g.
.*). That intent is correct; the mistake is that it also bypasseddirectory-level excludes, which is a stronger signal from the user.
The fix moves the
exclude_dirsloop above theendswithshortcut sothat directory exclusions are always evaluated first. Files that match
an exact include pattern but reside under an excluded directory are now
rejected, while files outside excluded directories continue to bypass
the pattern excludes as before.
A new unit test (pure
FileFilterinstantiation, no file-systemwatcher) reproduces the bug and confirms the fix: it asserts that
vendor/.dottedis not watched when.dottedis in--reload-includeand
vendor/is in--reload-exclude.