Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepend ./ for files specified as CLI args #1094

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def discover_files(self, targets, recursive=False, excluded_paths=""):
excluded_path_globs,
enforce_glob=False,
):
if fname != "-":
fname = os.path.join(".", fname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So let's say someone does something like bandit src/bandit/__init__.py, we still need to prepend this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't need to prepend in that case, but it also does no harm.

files_list.add(fname)
else:
excluded_files.add(fname)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/core/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def test_discover_files_exclude_glob(self, isdir):
self.manager.discover_files(
["a.py", "test_a.py", "test.py"], True, excluded_paths="test_*.py"
)
self.assertEqual(["a.py", "test.py"], self.manager.files_list)
self.assertEqual(["./a.py", "./test.py"], self.manager.files_list)
self.assertEqual(["test_a.py"], self.manager.excluded_files)

@mock.patch("os.path.isdir")
Expand All @@ -298,7 +298,7 @@ def test_discover_files_include(self, isdir):
with mock.patch.object(manager, "_is_file_included") as m:
m.return_value = True
self.manager.discover_files(["thing"], True)
self.assertEqual(["thing"], self.manager.files_list)
self.assertEqual(["./thing"], self.manager.files_list)
self.assertEqual([], self.manager.excluded_files)

def test_run_tests_keyboardinterrupt(self):
Expand Down