From 7943c73d3f26d731ee5d41344f811f2f4d1c0859 Mon Sep 17 00:00:00 2001 From: Stephane Rufer <1128559+rufman@users.noreply.github.com> Date: Fri, 23 Jun 2023 09:40:46 -0700 Subject: [PATCH] fix: add support for Dart SDK package dependencies (#1891) Signed-off-by: Stephane Rufer <1128559+rufman@users.noreply.github.com> --- syft/pkg/cataloger/dart/parse_pubspec_lock.go | 19 ++++++++++++++++++- .../cataloger/dart/parse_pubspec_lock_test.go | 13 +++++++++++++ .../cataloger/dart/test-fixtures/pubspec.lock | 5 +++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/syft/pkg/cataloger/dart/parse_pubspec_lock.go b/syft/pkg/cataloger/dart/parse_pubspec_lock.go index 3493f8d1df8..6de98c44a46 100644 --- a/syft/pkg/cataloger/dart/parse_pubspec_lock.go +++ b/syft/pkg/cataloger/dart/parse_pubspec_lock.go @@ -5,7 +5,7 @@ import ( "net/url" "sort" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "github.com/anchore/syft/internal/log" "github.com/anchore/syft/syft/artifact" @@ -38,6 +38,23 @@ type pubspecLockDescription struct { ResolvedRef string `yaml:"resolved-ref" mapstructure:"resolved-ref"` } +func (p *pubspecLockDescription) UnmarshalYAML(value *yaml.Node) error { + type pld pubspecLockDescription + var p2 pld + + if value.Decode(&p.Name) == nil { + return nil + } + + if err := value.Decode(&p2); err != nil { + return err + } + + *p = pubspecLockDescription(p2) + + return nil +} + func parsePubspecLock(_ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { var pkgs []pkg.Package diff --git a/syft/pkg/cataloger/dart/parse_pubspec_lock_test.go b/syft/pkg/cataloger/dart/parse_pubspec_lock_test.go index a5a972e80eb..6db99863d57 100644 --- a/syft/pkg/cataloger/dart/parse_pubspec_lock_test.go +++ b/syft/pkg/cataloger/dart/parse_pubspec_lock_test.go @@ -79,6 +79,19 @@ func TestParsePubspecLock(t *testing.T) { Version: "1.6.0", }, }, + { + Name: "flutter", + Version: "0.0.0", + PURL: "pkg:pub/flutter@0.0.0", + Locations: fixtureLocationSet, + Language: pkg.Dart, + Type: pkg.DartPubPkg, + MetadataType: pkg.DartPubMetadataType, + Metadata: pkg.DartPubMetadata{ + Name: "flutter", + Version: "0.0.0", + }, + }, { Name: "key_binder", Version: "1.11.20", diff --git a/syft/pkg/cataloger/dart/test-fixtures/pubspec.lock b/syft/pkg/cataloger/dart/test-fixtures/pubspec.lock index c7b912f1aef..da464c79527 100644 --- a/syft/pkg/cataloger/dart/test-fixtures/pubspec.lock +++ b/syft/pkg/cataloger/dart/test-fixtures/pubspec.lock @@ -36,6 +36,11 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" key_binder: dependency: "direct main" description: