diff --git a/bandit/cli/config_generator.py b/bandit/cli/config_generator.py index e46867f5e..b0569b1e2 100644 --- a/bandit/cli/config_generator.py +++ b/bandit/cli/config_generator.py @@ -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): diff --git a/bandit/cli/main.py b/bandit/cli/main.py index 47588859d..bb03f4cda 100644 --- a/bandit/cli/main.py +++ b/bandit/cli/main.py @@ -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: diff --git a/bandit/core/config.py b/bandit/core/config.py index 236f357c5..66ad26d22 100644 --- a/bandit/core/config.py +++ b/bandit/core/config.py @@ -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) diff --git a/bandit/core/utils.py b/bandit/core/utils.py index 3ac78f54f..4b63eed44 100644 --- a/bandit/core/utils.py +++ b/bandit/core/utils.py @@ -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(