Skip to content

Commit

Permalink
fixin bug in jsonsaver - avoid producing "Files: null" and "Snippets:…
Browse files Browse the repository at this point in the history
… null" if saveing a package without files (filesAnalyzed is false)

Signed-off-by: Yan Yagudayev <yanyag@gmail.com>
  • Loading branch information
yanyag committed Nov 25, 2021
1 parent 1d27f44 commit a6b19d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jsonsaver/saver2v2/save_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func RenderDocument2_2(doc *spdx.Document2_2, buf *bytes.Buffer) error {
}

// save files and snippets from spdx to json
if allfiles != nil {
if len(allfiles) > 0 {
_, err = renderFiles2_2(doc, jsondocument, allfiles)
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions jsonsaver/saver2v2/save_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func TestRenderDocument2_2(t *testing.T) {
RefB: spdx.DocElementID{DocumentRefID: "", ElementRefID: "Package"},
Relationship: "CONTAINS",
},
{
RefA: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"},
RefB: spdx.DocElementID{DocumentRefID: "", ElementRefID: "p1"},
Relationship: "CONTAINS",
},
{
RefA: spdx.DocElementID{DocumentRefID: "", ElementRefID: "DOCUMENT"},
RefB: spdx.DocElementID{DocumentRefID: "", ElementRefID: "File"},
Expand Down Expand Up @@ -255,6 +260,11 @@ func TestRenderDocument2_2(t *testing.T) {
"relatedSpdxElement": "SPDXRef-Package",
"relationshipType": "CONTAINS",
},
map[string]interface{}{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-p1",
"relationshipType": "CONTAINS",
},
map[string]interface{}{
"spdxElementId": "SPDXRef-DOCUMENT",
"relatedSpdxElement": "SPDXRef-File",
Expand Down

0 comments on commit a6b19d6

Please sign in to comment.