mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
empty source during decoding should not be fatal (#3791)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
parent
e7f0a602c2
commit
24df095a5e
@ -58,7 +58,8 @@ func (s *Source) UnmarshalJSON(b []byte) error {
|
|||||||
func unpackSrcMetadata(s *Source, unpacker sourceUnpacker) error {
|
func unpackSrcMetadata(s *Source, unpacker sourceUnpacker) error {
|
||||||
rt := sourcemetadata.ReflectTypeFromJSONName(s.Type)
|
rt := sourcemetadata.ReflectTypeFromJSONName(s.Type)
|
||||||
if rt == nil {
|
if rt == nil {
|
||||||
return fmt.Errorf("unable to find source metadata type=%q", s.Type)
|
// in cases where we are converting from an SBOM without any source information, we don't want this to be fatal
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
val := reflect.New(rt).Interface()
|
val := reflect.New(rt).Interface()
|
||||||
|
|||||||
@ -22,6 +22,15 @@ func TestSource_UnmarshalJSON(t *testing.T) {
|
|||||||
expected *Source
|
expected *Source
|
||||||
wantErr require.ErrorAssertionFunc
|
wantErr require.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
input: []byte(`{
|
||||||
|
"id": "",
|
||||||
|
"type": "",
|
||||||
|
"metadata": null
|
||||||
|
}`),
|
||||||
|
expected: &Source{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "directory",
|
name: "directory",
|
||||||
input: []byte(`{
|
input: []byte(`{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user