Skip to content

Commit 5ab96c7

Browse files
committed
Improve detection of "nosec" clause
1 parent 8a43ec4 commit 5ab96c7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

bandit/core/manager.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,14 @@ def _parse_file(self, fname, fdata, new_files_list):
264264
lines = data.splitlines()
265265
self.metrics.begin(fname)
266266
self.metrics.count_locs(lines)
267-
if self.ignore_nosec:
268-
nosec_lines = set()
267+
268+
nosec_lines = set()
269+
if not six.PY2 and isinstance(data, bytes):
270+
has_nosec = b'nosec' in data
269271
else:
272+
has_nosec = 'nosec' in data
273+
274+
if not self.ignore_nosec and has_nosec:
270275
try:
271276
fdata.seek(0)
272277
if six.PY2:

tests/functional/test_runtime.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ def test_example_nonsense2(self):
103103
)
104104
self.assertEqual(0, retcode)
105105
self.assertIn("Files skipped (1):", output)
106-
if six.PY2:
107-
self.assertIn("nonsense2.py (exception while scanning file)",
108-
output)
109-
else:
110-
self.assertIn("nonsense2.py (syntax error while parsing AST",
111-
output)
106+
self.assertIn("nonsense2.py (exception while scanning file)", output)
112107

113108
def test_example_imports(self):
114109
(retcode, output) = self._test_example(['bandit', ], ['imports.py', ])

0 commit comments

Comments
 (0)