Skip to content

Commit

Permalink
fix(purl): handle rust types (#5186)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Sep 15, 2023
1 parent 81240cf commit daae882
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pkg/purl/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ func purlType(t string) string {
return packageurl.TypeConan
case ftypes.Pub:
return TypeDart // TODO: replace with packageurl.TypeDart once they add it.
case ftypes.RustBinary, ftypes.Cargo:
return packageurl.TypeCargo
case os.Alpine:
return TypeAPK
case os.Debian, os.Ubuntu:
Expand Down
29 changes: 25 additions & 4 deletions pkg/purl/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ func TestNewPackageURL(t *testing.T) {
name: "hex package",
typ: ftypes.Hex,
pkg: ftypes.Package{
ID: "[email protected]",
Name: "bunt",
Version: "0.2.0",
Locations: []ftypes.Location{{StartLine: 2, EndLine: 2}},
ID: "[email protected]",
Name: "bunt",
Version: "0.2.0",
Locations: []ftypes.Location{
{
StartLine: 2,
EndLine: 2,
},
},
},
want: purl.PackageURL{
PackageURL: packageurl.PackageURL{
Expand Down Expand Up @@ -247,6 +252,22 @@ func TestNewPackageURL(t *testing.T) {
},
},
},
{
name: "rust binary",
typ: ftypes.RustBinary,
pkg: ftypes.Package{
ID: "[email protected]",
Name: "abomonation",
Version: "0.7.3",
},
want: purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeCargo,
Name: "abomonation",
Version: "0.7.3",
},
},
},
{
name: "os package",
typ: os.RedHat,
Expand Down

0 comments on commit daae882

Please sign in to comment.