From 7f87a9e283418f194f9208a8a8211478663a1c4c Mon Sep 17 00:00:00 2001 From: Bart Kamphorst Date: Thu, 11 May 2023 14:43:02 +0200 Subject: [PATCH] fix: correct no-prefix no-suffix exclude for top-level dirs Resolves #975 --- bandit/core/manager.py | 3 --- tests/unit/core/test_manager.py | 8 ++++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bandit/core/manager.py b/bandit/core/manager.py index 02fed5c3..470219fd 100644 --- a/bandit/core/manager.py +++ b/bandit/core/manager.py @@ -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 diff --git a/tests/unit/core/test_manager.py b/tests/unit/core/test_manager.py index 72686bf8..b0551251 100644 --- a/tests/unit/core/test_manager.py +++ b/tests/unit/core/test_manager.py @@ -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)