Skip to content

Commit daae882

Browse files
authored
fix(purl): handle rust types (#5186)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
1 parent 81240cf commit daae882

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

pkg/purl/purl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ func purlType(t string) string {
375375
return packageurl.TypeConan
376376
case ftypes.Pub:
377377
return TypeDart // TODO: replace with packageurl.TypeDart once they add it.
378+
case ftypes.RustBinary, ftypes.Cargo:
379+
return packageurl.TypeCargo
378380
case os.Alpine:
379381
return TypeAPK
380382
case os.Debian, os.Ubuntu:

pkg/purl/purl_test.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,15 @@ func TestNewPackageURL(t *testing.T) {
185185
name: "hex package",
186186
typ: ftypes.Hex,
187187
pkg: ftypes.Package{
188-
ID: "bunt@0.2.0",
189-
Name: "bunt",
190-
Version: "0.2.0",
191-
Locations: []ftypes.Location{{StartLine: 2, EndLine: 2}},
188+
ID: "bunt@0.2.0",
189+
Name: "bunt",
190+
Version: "0.2.0",
191+
Locations: []ftypes.Location{
192+
{
193+
StartLine: 2,
194+
EndLine: 2,
195+
},
196+
},
192197
},
193198
want: purl.PackageURL{
194199
PackageURL: packageurl.PackageURL{
@@ -247,6 +252,22 @@ func TestNewPackageURL(t *testing.T) {
247252
},
248253
},
249254
},
255+
{
256+
name: "rust binary",
257+
typ: ftypes.RustBinary,
258+
pkg: ftypes.Package{
259+
ID: "abomonation@0.7.3",
260+
Name: "abomonation",
261+
Version: "0.7.3",
262+
},
263+
want: purl.PackageURL{
264+
PackageURL: packageurl.PackageURL{
265+
Type: packageurl.TypeCargo,
266+
Name: "abomonation",
267+
Version: "0.7.3",
268+
},
269+
},
270+
},
250271
{
251272
name: "os package",
252273
typ: os.RedHat,

0 commit comments

Comments
 (0)