Skip to content

Commit f32004e

Browse files
fix: fix npm namespace encoding for ecosystem.ms (#57)
Closes #56
1 parent e5db958 commit f32004e

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

lib/ecosystems/package.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package ecosystems
1919
import (
2020
"context"
2121
"fmt"
22-
"net/url"
2322

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

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

87-
// ecosyste.ms npm requires the combination of namespace and name to
88-
// be URL-encoded, including the separator.
89-
case packageurl.TypeNPM:
90-
name = url.QueryEscape(fmt.Sprintf("%s/%s", purl.Namespace, purl.Name))
91-
9286
// apk packages are only used by alpine, so the namespace isn't used in the
9387
// package name for the ecosyste.ms API
9488
case packageurl.TypeApk:
9589
break
9690
}
97-
9891
return name
9992
}

lib/ecosystems/package_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package ecosystems
1818

1919
import (
2020
"fmt"
21-
"net/url"
2221
"testing"
2322

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

0 commit comments

Comments
 (0)