From 6d25b5bc2600aa5630fe91e98d0a4040e907b55d Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Thu, 21 Sep 2023 12:22:58 -0400 Subject: [PATCH] fix(2.2 json): remove emtpy packageVerificationCode Signed-off-by: Keith Zantow --- spdx/v2/v2_2/package.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spdx/v2/v2_2/package.go b/spdx/v2/v2_2/package.go index 54de537..700c83e 100644 --- a/spdx/v2/v2_2/package.go +++ b/spdx/v2/v2_2/package.go @@ -4,6 +4,7 @@ package v2_2 import ( "encoding/json" + "regexp" "strings" "github.com/spdx/tools-golang/spdx/v2/common" @@ -122,6 +123,20 @@ type Package struct { hasFiles []common.DocElementID } +var emptyVerificationCodeRegex = regexp.MustCompile(`,\s*"packageVerificationCode"\s*:\s*\{\s*"packageVerificationCodeValue"\s*:\s*""\s*}`) + +func (p *Package) MarshalJSON() ([]byte, error) { + type pkg Package + p2 := pkg(*p) + + data, err := json.Marshal(p2) + if err != nil { + return nil, err + } + + return emptyVerificationCodeRegex.ReplaceAll(data, []byte("")), nil +} + func (p *Package) UnmarshalJSON(b []byte) error { type pkg Package type extras struct { @@ -153,6 +168,7 @@ func (p *Package) UnmarshalJSON(b []byte) error { } var _ json.Unmarshaler = (*Package)(nil) +var _ json.Marshaler = (*Package)(nil) // PackageExternalReference is an External Reference to additional info // about a Package, as defined in section 7.21 in version 2.2 of the spec.