diff --git a/pkg/contexts/ocm/accessmethods/npm/method.go b/pkg/contexts/ocm/accessmethods/npm/method.go index 95ed19e244..7d70ecb217 100644 --- a/pkg/contexts/ocm/accessmethods/npm/method.go +++ b/pkg/contexts/ocm/accessmethods/npm/method.go @@ -98,12 +98,12 @@ func (a *AccessSpec) GetInexpensiveContentVersionIdentity(access accspeccpi.Comp // PackageUrl returns the URL of the NPM package (Registry/Package). func (a *AccessSpec) PackageUrl() string { - return a.Registry[:8] + path.Clean(path.Join(a.Registry[8:], a.Package)) + return strings.TrimSuffix(a.Registry, "/") + path.Join("/", a.Package) } // PackageVersionUrl returns the URL of the NPM package-version (Registry/Package/Version). func (a *AccessSpec) PackageVersionUrl() string { - return a.Registry[:8] + path.Clean(path.Join(a.PackageUrl()[8:], a.Version)) + return strings.TrimSuffix(a.Registry, "/") + path.Join("/", a.Package, a.Version) } func (a *AccessSpec) GetPackageVersion(ctx accspeccpi.Context) (*npm.Version, error) { diff --git a/pkg/contexts/ocm/accessmethods/npm/method_test.go b/pkg/contexts/ocm/accessmethods/npm/method_test.go index cf6b69532b..97c8ec7630 100644 --- a/pkg/contexts/ocm/accessmethods/npm/method_test.go +++ b/pkg/contexts/ocm/accessmethods/npm/method_test.go @@ -69,10 +69,6 @@ var _ = Describe("Method", func() { Expect(acc.PackageUrl()).To(Equal(packageUrl)) acc = npm.New("https://registry.npmjs.org/", "yargs", "17.7.1") Expect(acc.PackageUrl()).To(Equal(packageUrl)) - acc = npm.New("https://registry.npmjs.org/", "/yargs", "/17.7.1") - Expect(acc.PackageUrl()).To(Equal(packageUrl)) - acc = npm.New("https://registry.npmjs.org//", "yargs", "17.7.1") - Expect(acc.PackageUrl()).To(Equal(packageUrl)) }) It("PackageVersionUrl()", func() { @@ -81,9 +77,5 @@ var _ = Describe("Method", func() { Expect(acc.PackageVersionUrl()).To(Equal(packageVersionUrl)) acc = npm.New("https://registry.npmjs.org/", "yargs", "17.7.1") Expect(acc.PackageVersionUrl()).To(Equal(packageVersionUrl)) - acc = npm.New("https://registry.npmjs.org/", "/yargs", "/17.7.1") - Expect(acc.PackageVersionUrl()).To(Equal(packageVersionUrl)) - acc = npm.New("https://registry.npmjs.org//", "yargs", "17.7.1") - Expect(acc.PackageVersionUrl()).To(Equal(packageVersionUrl)) }) })