Fix --exclude with bare directory names when scanning with -r .#1366
Open
stefanoginella wants to merge 1 commit intoPyCQA:mainfrom
Open
Fix --exclude with bare directory names when scanning with -r .#1366stefanoginella wants to merge 1 commit intoPyCQA:mainfrom
stefanoginella wants to merge 1 commit intoPyCQA:mainfrom
Conversation
When scanning with -r ., os.walk yields ./-prefixed paths (e.g., ./venv/file.py). The discover_files method converts bare directory names to glob patterns (venv -> venv/*), but neither fnmatch nor substring matching catches the ./-prefixed walked paths. Apply os.path.normpath in three places: - _is_file_included: normalize the path before matching - _get_files_from_dir: normalize walked paths before checking - discover_files: normalize --exclude paths before glob conversion Resolves: PyCQA#975 See also: PyCQA#966
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.
Summary
--excludeflag silently failing when bare directory names (e.g.,venvinstead of./venv) are passed while scanning with-r .os.walk(".")yields./-prefixed paths, but excluded dirs become glob patterns (e.g.,venv/*) that don't match the./-prefixed paths in eitherfnmatchor substring checksos.path.normpath()to normalize paths consistently before comparisonTest plan
test_get_files_from_dir_excludes_dot_prefixed_pathscovering the os.walk ./-prefix scenariotest_discover_files_exclude_dirwith a case for bare dir names when the directory existsbandit -r . --exclude excluded_dirnow correctly excludes the directoryResolves #975
See also #966