Skip to content

Commit 541a8fa

Browse files
committed
Improve detection of "nosec" clause
1 parent 8a43ec4 commit 541a8fa

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
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-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import subprocess
77

8-
import six
98
import testtools
109

1110

@@ -103,12 +102,7 @@ def test_example_nonsense2(self):
103102
)
104103
self.assertEqual(0, retcode)
105104
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)
105+
self.assertIn("nonsense2.py (exception while scanning file)", output)
112106

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

0 commit comments

Comments
 (0)