From 5f001aa388e2b2b60e34f69724421ce5efd8c749 Mon Sep 17 00:00:00 2001 From: Shivam-nagar23 Date: Thu, 7 Dec 2023 21:04:16 +0530 Subject: [PATCH] invalid json --- common/bean.go | 8 ++++++++ pkg/security/ImageScanService.go | 1 + 2 files changed, 9 insertions(+) diff --git a/common/bean.go b/common/bean.go index 665b65a5d..5ee4af83d 100644 --- a/common/bean.go +++ b/common/bean.go @@ -3,6 +3,7 @@ package common import ( "github.com/optiopay/klar/clair" "github.com/quay/claircore" + "strings" "time" ) @@ -124,3 +125,10 @@ type SeverityCount struct { Moderate int `json:"moderate"` Low int `json:"low"` } + +func RemoveTrailingComma(jsonString string) string { + if strings.HasSuffix(jsonString, ",]") { + return jsonString[:len(jsonString)-2] + jsonString[len(jsonString)-1:] + } + return jsonString +} diff --git a/pkg/security/ImageScanService.go b/pkg/security/ImageScanService.go index d0f574ee9..845973a77 100644 --- a/pkg/security/ImageScanService.go +++ b/pkg/security/ImageScanService.go @@ -379,6 +379,7 @@ func (impl *ImageScanServiceImpl) ConvertEndStepOutputAndSaveVulnerabilities(ste impl.logger.Errorw("error in parsing template to get vulnerabilities", "err", err) return err } + renderedTemplate = common.RemoveTrailingComma(renderedTemplate) var vulnerabilities []*bean.ImageScanOutputObject err = json.Unmarshal([]byte(renderedTemplate), &vulnerabilities) if err != nil {