Skip to content

Commit

Permalink
fix: correct no-prefix no-suffix exclude for top-level dirs
Browse files Browse the repository at this point in the history
Resolves PyCQA#975
  • Loading branch information
b-kamphorst committed May 11, 2023
1 parent f1a3295 commit 0ede84d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 0 additions & 3 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@ def discover_files(self, targets, recursive=False, excluded_paths=""):
# if there are command line provided exclusions add them to the list
if excluded_paths:
for path in excluded_paths.split(","):
if os.path.isdir(path):
path = os.path.join(path, "*")

excluded_path_globs.append(path)

# build list of files we will analyze
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/core/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,25 @@ def test_discover_files_exclude_dir(self, isdir):
self.assertEqual(["./x/y.py"], self.manager.excluded_files)

# Test exclude dir without wildcard
isdir.side_effect = [True, False]
isdir.side_effect = [False]
self.manager.discover_files(["./x/y.py"], True, "./x/")
self.assertEqual([], self.manager.files_list)
self.assertEqual(["./x/y.py"], self.manager.excluded_files)

# Test exclude dir without wildcard or trailing slash
isdir.side_effect = [True, False]
isdir.side_effect = [False]
self.manager.discover_files(["./x/y.py"], True, "./x")
self.assertEqual([], self.manager.files_list)
self.assertEqual(["./x/y.py"], self.manager.excluded_files)

# Test exclude top-level dir without prefix or suffix
isdir.side_effect = [True, False]
isdir.side_effect = [False]
self.manager.discover_files(["./x/y/z.py"], True, "x")
self.assertEqual([], self.manager.files_list)
self.assertEqual(["./x/y/z.py"], self.manager.excluded_files)

# Test exclude lower-level dir without prefix or suffix
isdir.side_effect = [False, False]
isdir.side_effect = [False]
self.manager.discover_files(["./x/y/z.py"], True, "y")
self.assertEqual([], self.manager.files_list)
self.assertEqual(["./x/y/z.py"], self.manager.excluded_files)
Expand Down

0 comments on commit 0ede84d

Please sign in to comment.