diff --git a/pkg/report/validate.go b/pkg/report/validate.go index f4e059b092..4f0f451d54 100644 --- a/pkg/report/validate.go +++ b/pkg/report/validate.go @@ -1,6 +1,12 @@ package report -import "strings" +import ( + "regexp" +) + +// check for json and {{json }} which is not valid go template, +// {{json .}} is valid and thus not matched +var jsonRegex = regexp.MustCompile(`^\s*(json|{{\s*json\s*}})\s*$`) // JSONFormat test CLI --format string to be a JSON request // @@ -8,5 +14,5 @@ import "strings" // ... process JSON and output // } func IsJSON(s string) bool { - return strings.TrimSpace(s) == "json" + return jsonRegex.MatchString(s) } diff --git a/pkg/report/validate_test.go b/pkg/report/validate_test.go index 3e21e4550a..242634c82a 100644 --- a/pkg/report/validate_test.go +++ b/pkg/report/validate_test.go @@ -17,8 +17,8 @@ func TestIsJSON(t *testing.T) { {" json", true}, {" json ", true}, {" json ", true}, - {"{{json}}", false}, - {"{{json }}", false}, + {"{{json}}", true}, + {"{{json }}", true}, {"{{json .}}", false}, {"{{ json .}}", false}, {"{{ json . }}", false},