Skip to content

Commit

Permalink
Improve detection of "nosec" clause
Browse files Browse the repository at this point in the history
  • Loading branch information
ehooo committed Feb 27, 2020
1 parent 8a43ec4 commit 541a8fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 7 additions & 2 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ def _parse_file(self, fname, fdata, new_files_list):
lines = data.splitlines()
self.metrics.begin(fname)
self.metrics.count_locs(lines)
if self.ignore_nosec:
nosec_lines = set()

nosec_lines = set()
if not six.PY2 and isinstance(data, bytes):
has_nosec = b'nosec' in data
else:
has_nosec = 'nosec' in data

if not self.ignore_nosec and has_nosec:
try:
fdata.seek(0)
if six.PY2:
Expand Down
8 changes: 1 addition & 7 deletions tests/functional/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import subprocess

import six
import testtools


Expand Down Expand Up @@ -103,12 +102,7 @@ def test_example_nonsense2(self):
)
self.assertEqual(0, retcode)
self.assertIn("Files skipped (1):", output)
if six.PY2:
self.assertIn("nonsense2.py (exception while scanning file)",
output)
else:
self.assertIn("nonsense2.py (syntax error while parsing AST",
output)
self.assertIn("nonsense2.py (exception while scanning file)", output)

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

0 comments on commit 541a8fa

Please sign in to comment.