Skip to content

Commit

Permalink
handle long text into new line
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Kumar Sahu <[email protected]>
  • Loading branch information
viveksahu26 committed Nov 26, 2024
1 parent 9587f8d commit bfe3eeb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/compliance/bsiV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/compliance/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion pkg/sbom/spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions samples/sbomqs-dummy-bomlinks-data.spdx.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"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"
}
},
{
"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"
Expand Down

0 comments on commit bfe3eeb

Please sign in to comment.