Skip to content
Open
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
4 changes: 2 additions & 2 deletions bandit/cli/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def main():

try:
with open(args.output_file, "w") as f:
skips = args.skips.split(",") if args.skips else []
tests = args.tests.split(",") if args.tests else []
skips = args.skips if args.skips else []
tests = args.tests if args.tests else []

for skip in skips:
if not extension_loader.MANAGER.check_id(skip):
Expand Down
4 changes: 2 additions & 2 deletions bandit/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ def main():
profile = _get_profile(b_conf, args.profile, args.config_file)
_log_info(args, profile)

profile["include"].update(args.tests.split(",") if args.tests else [])
profile["exclude"].update(args.skips.split(",") if args.skips else [])
profile["include"].update(args.tests if args.tests else [])
profile["exclude"].update(args.skips if args.skips else [])
extension_mgr.validate_profile(profile)

except (utils.ProfileNotFound, ValueError) as e:
Expand Down
17 changes: 11 additions & 6 deletions bandit/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ def __init__(self, config_file=None):
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
else:
try:
with f:
self._config = yaml.safe_load(f)
except yaml.YAMLError as err:
LOG.error(err)
raise utils.ConfigError("Error parsing file.", config_file)
self._config = utils.parse_ini_file(config_file)
if not self._config:
try:
with f:
self._config = yaml.safe_load(f)
except yaml.YAMLError as err:
LOG.error(err)
raise utils.ConfigError(
"Error parsing YAML file.",
config_file
)

self.validate(config_file)

Expand Down
5 changes: 4 additions & 1 deletion bandit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ def parse_ini_file(f_loc):
config = configparser.ConfigParser()
try:
config.read(f_loc)
return {k: v for k, v in config.items("bandit")}
d = {k: v for k, v in config.items("bandit")}
for k in ("skips", "tests"):
d[k] = d[k].split(",") if k in d else []
return d

except (configparser.Error, KeyError, TypeError):
LOG.warning(
Expand Down