From 0ede84d8189134ff25ceeb96a9ab499c8bbfaa95 Mon Sep 17 00:00:00 2001 From: Bart Kamphorst Date: Thu, 11 May 2023 14:04:39 +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 02fed5c30..470219fdc 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 72686bf84..b05512512 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)