Skip to content

Commit

Permalink
strings.TrimSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf committed May 29, 2024
1 parent 0aa2829 commit 43fd92f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/contexts/ocm/accessmethods/npm/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 0 additions & 8 deletions pkg/contexts/ocm/accessmethods/npm/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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))
})
})

0 comments on commit 43fd92f

Please sign in to comment.