Skip to content

Commit

Permalink
fix: apk package lookup for ecosyste.ms doesn't use the namespace (#40)
Browse files Browse the repository at this point in the history
* fix: apk package lookup for ecosyste.ms doesn't use the namespace

* refactor: fixed typo, break in apk case

---------

Co-authored-by: Maximilian Combüchen <max.combuchen@snyk.io>
  • Loading branch information
garethr and mcombuechen authored Feb 1, 2024
1 parent cb64f57 commit 60602d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ecosystems/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ func purlToEcosystemsName(purl packageurl.PackageURL) string {
default:
name = fmt.Sprintf("%s/%s", purl.Namespace, purl.Name)

// Ecosystem maven requires the group ID and artifact ID to be separated
// ecosyste.ms maven requires the group ID and artifact ID to be separated
// by a colon ":",
case packageurl.TypeMaven:
name = fmt.Sprintf("%s:%s", purl.Namespace, purl.Name)

// Ecosystem npm requires the combination of namespace and name to
// ecosyste.ms npm requires the combination of namespace and name to
// be URL-encoded, including the separator.
case packageurl.TypeNPM:
name = url.QueryEscape(fmt.Sprintf("%s/%s", purl.Namespace, purl.Name))

// apk packages are only used by alpine, so the namespace isn't used in the
// package name for the ecosyste.ms API
case packageurl.TypeApk:
break
}

return name
Expand Down
5 changes: 5 additions & 0 deletions lib/ecosystems/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func TestPurlToEcosystemsName(t *testing.T) {
purlStr: "pkg:swift/github.com/yonaskolb/XcodeGen@1",
expectedName: "github.com/yonaskolb/XcodeGen",
},
{
// Test case 8: When the package manager type is "apk"
purlStr: "pkg:apk/alpine/lf@30-r3",
expectedName: "lf",
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit 60602d5

Please sign in to comment.