Skip to content

Commit

Permalink
fix: fix npm namespace encoding for ecosystem.ms (#57)
Browse files Browse the repository at this point in the history
Closes #56
  • Loading branch information
paulrosca-snyk authored Feb 16, 2024
1 parent e5db958 commit f32004e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
7 changes: 0 additions & 7 deletions lib/ecosystems/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ecosystems
import (
"context"
"fmt"
"net/url"

"github.com/package-url/packageurl-go"

Expand Down Expand Up @@ -84,16 +83,10 @@ func purlToEcosystemsName(purl packageurl.PackageURL) string {
case packageurl.TypeMaven:
name = fmt.Sprintf("%s:%s", purl.Namespace, purl.Name)

// 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
}
5 changes: 2 additions & 3 deletions lib/ecosystems/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package ecosystems

import (
"fmt"
"net/url"
"testing"

"github.com/jarcoal/httpmock"
Expand Down Expand Up @@ -89,8 +88,8 @@ func TestPurlToEcosystemsName(t *testing.T) {
// Test case 1: When the package manager type is "npm"
// and the namespace is not empty, the function should return
// a url encoded string in the form of "<namespace>/<name>"
purlStr: "pkg:npm/my-namespace/my-package",
expectedName: url.QueryEscape("my-namespace/my-package"),
purlStr: "pkg:npm/%40my-namespace/my-package",
expectedName: "@my-namespace/my-package",
},
{
// Test case 2: When the package manager type is "npm"
Expand Down

0 comments on commit f32004e

Please sign in to comment.