diff --git a/checkov/common/runners/runner_registry.py b/checkov/common/runners/runner_registry.py index d4c87b5fb1..4865e8a456 100644 --- a/checkov/common/runners/runner_registry.py +++ b/checkov/common/runners/runner_registry.py @@ -391,8 +391,17 @@ def print_reports( ) -> Literal[0, 1]: output_formats: "dict[str, str]" = {} - if config.output_file_path and "," in config.output_file_path: - output_paths = config.output_file_path.split(",") + if config.output_file_path: + output_paths = [output_file.strip() for output_file in config.output_file_path.split(",") if output_file.strip()] + diff = len(output_paths) - len(config.output) + + # In case the output formats specified is greater than the number + # of the output file paths given, + # print others to console(stdout). + # In case diff > 0, we can safely ignore the extra output file paths. + if diff < 0: + # avoids out of bounds. + output_paths.extend(CONSOLE_OUTPUT for output_format in range(-diff)) for idx, output_format in enumerate(config.output): output_formats[output_format] = output_paths[idx] else: diff --git a/tests/common/runner_registry/test_runner_registry.py b/tests/common/runner_registry/test_runner_registry.py index c8b835d88b..e64f54644d 100644 --- a/tests/common/runner_registry/test_runner_registry.py +++ b/tests/common/runner_registry/test_runner_registry.py @@ -740,6 +740,79 @@ def test_output_file_path_with_output_mapping(tmp_path: Path, capsys: CaptureFix assert xml_file_path.exists() assert "