From 70bcd60fbdf6f8441be61cbfeb8d0fdf391c8e79 Mon Sep 17 00:00:00 2001 From: sundowndev Date: Mon, 28 Feb 2022 11:48:14 +0400 Subject: [PATCH] fix: use voidprinter for html output We should not print anything but the scan output when we send output to stdout. --- pkg/cmd/scan/output/output.go | 5 +++++ pkg/cmd/scan/output/output_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/cmd/scan/output/output.go b/pkg/cmd/scan/output/output.go index 73248aa2..048db909 100644 --- a/pkg/cmd/scan/output/output.go +++ b/pkg/cmd/scan/output/output.go @@ -89,6 +89,11 @@ func GetPrinter(config OutputConfig, quiet bool) output.Printer { return &output.VoidPrinter{} } fallthrough + case HTMLOutputType: + if isStdOut(config.Path) { + return &output.VoidPrinter{} + } + fallthrough case ConsoleOutputType: fallthrough default: diff --git a/pkg/cmd/scan/output/output_test.go b/pkg/cmd/scan/output/output_test.go index efb2af1d..068031f9 100644 --- a/pkg/cmd/scan/output/output_test.go +++ b/pkg/cmd/scan/output/output_test.go @@ -529,6 +529,18 @@ func TestGetPrinter(t *testing.T) { key: PlanOutputType, want: &output.VoidPrinter{}, }, + { + name: "html stdout output", + path: "stdout", + key: HTMLOutputType, + want: &output.VoidPrinter{}, + }, + { + name: "html /dev/stdout output", + path: "/dev/stdout", + key: HTMLOutputType, + want: &output.VoidPrinter{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {