From ce6346de9c5ea83cb8bf3d65d6827b4e51f6875a Mon Sep 17 00:00:00 2001 From: ehooo Date: Thu, 27 Feb 2020 23:10:31 +0100 Subject: [PATCH] Improve detection of "nosec" clause --- bandit/core/manager.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bandit/core/manager.py b/bandit/core/manager.py index 956d0673b..298812c2d 100644 --- a/bandit/core/manager.py +++ b/bandit/core/manager.py @@ -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: