Skip to content

Commit

Permalink
fix: add support for Dart SDK package dependencies (#1891)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephane Rufer <1128559+rufman@users.noreply.github.com>
  • Loading branch information
rufman authored Jun 23, 2023
1 parent 25ce245 commit 7943c73
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
19 changes: 18 additions & 1 deletion syft/pkg/cataloger/dart/parse_pubspec_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions syft/pkg/cataloger/dart/parse_pubspec_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions syft/pkg/cataloger/dart/test-fixtures/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7943c73

Please sign in to comment.