From bfe3eeb54c761ba563fa6d353d2ba43c6db20c71 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Sahu Date: Tue, 26 Nov 2024 18:38:36 +0530 Subject: [PATCH] handle long text into new line Signed-off-by: Vivek Kumar Sahu --- pkg/compliance/bsiV2.go | 2 ++ pkg/compliance/common/common.go | 14 ++++++++++++++ pkg/sbom/spdx.go | 2 +- samples/sbomqs-dummy-bomlinks-data.spdx.json | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/compliance/bsiV2.go b/pkg/compliance/bsiV2.go index 6e97b80..e351f76 100644 --- a/pkg/compliance/bsiV2.go +++ b/pkg/compliance/bsiV2.go @@ -70,6 +70,8 @@ func bsiV2SbomLinks(doc sbom.Document) *db.Record { result = strings.Join(bom, ", ") score = 10.0 } + wrappedURL := common.WrapText(result, 80) + result = wrappedURL return db.NewRecordStmt(SBOM_BOM_LINKS, "doc", result, score, "") } diff --git a/pkg/compliance/common/common.go b/pkg/compliance/common/common.go index 21c97cf..492eced 100644 --- a/pkg/compliance/common/common.go +++ b/pkg/compliance/common/common.go @@ -375,3 +375,17 @@ func IsComponentPartOfPrimaryDependency(primaryCompDeps []string, comp string) b } return false } + +func WrapText(input string, maxWidth int) string { + var result []string + for len(input) > maxWidth { + splitPoint := strings.LastIndex(input[:maxWidth], "/") + if splitPoint == -1 { + splitPoint = maxWidth + } + result = append(result, input[:splitPoint]) + input = input[splitPoint:] + } + result = append(result, input) + return strings.Join(result, "\n") +} diff --git a/pkg/sbom/spdx.go b/pkg/sbom/spdx.go index 52fb78b..37ab198 100644 --- a/pkg/sbom/spdx.go +++ b/pkg/sbom/spdx.go @@ -199,7 +199,7 @@ func (s *SpdxDoc) parseSpec() { if s.doc.ExternalDocumentReferences != nil { for _, bom := range s.doc.ExternalDocumentReferences { - sp.ExternalDocReference = append(sp.ExternalDocReference, bom.DocumentRefID) + sp.ExternalDocReference = append(sp.ExternalDocReference, bom.URI) } } diff --git a/samples/sbomqs-dummy-bomlinks-data.spdx.json b/samples/sbomqs-dummy-bomlinks-data.spdx.json index 6fd9d0d..6fb63a7 100644 --- a/samples/sbomqs-dummy-bomlinks-data.spdx.json +++ b/samples/sbomqs-dummy-bomlinks-data.spdx.json @@ -15,7 +15,7 @@ "externalDocumentRefs": [ { "externalDocumentId": "DocumentRef-InterlynkSBOM", - "spdxDocumentNamespace": "https://interlynk.io/github.com%2Finterlynk-io%2Fsbomqs/0.0.15/qIP32aoJi0u5M_EjHeJHAg", + "spdxDocument": "https://interlynk.io/github.com%2Finterlynk-io%2Fsbomqs/0.0.15/qIP32aoJi0u5M_EjHeJHAg", "checksum": { "algorithm": "SHA256", "checksumValue": "09e46d45422cc6ab9a6dc1d57ad4d27687fc47fcfac5b732d8bb07327c11e8c3" @@ -23,7 +23,7 @@ }, { "externalDocumentId": "DocumentRef-ToolsetX-v1.2", - "spdxDocumentNamespace": "https://example.com/spdx/docs/toolsetX-v1.2", + "spdxDocument": "https://example.com/spdx/docs/toolsetX-v1.2", "checksum": { "algorithm": "SHA256", "checksumValue": "4a9c983fd1ae8347dd53c897bc9c38df2f7d6ab98775bf8c36c1237cd123b4e6"