Skip to content

Commit

Permalink
fix(purl): trim a final slash
Browse files Browse the repository at this point in the history
  • Loading branch information
javierfreire committed Sep 14, 2023
1 parent 81240cf commit 3ab655e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/purl/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ func parseQualifier(pkg ftypes.Package) packageurl.Qualifiers {

func parsePkgName(name string) (string, string) {
var namespace string
if len(name) > 0 && name[len(name)-1] == '/' {
name = name[:len(name)-1]
}
index := strings.LastIndex(name, "/")
if index != -1 {
namespace = name[:index]
Expand Down
16 changes: 16 additions & 0 deletions pkg/purl/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ func TestNewPackageURL(t *testing.T) {
},
},
},
{
name: "golang package with a local path",
typ: ftypes.GoModule,
pkg: ftypes.Package{
Name: "./private_repos/cnrm.googlesource.com/cnrm/",
Version: "(devel)",
},
want: purl.PackageURL{
PackageURL: packageurl.PackageURL{
Type: packageurl.TypeGolang,
Namespace: "./private_repos/cnrm.googlesource.com",
Name: "cnrm",
Version: "(devel)",
},
},
},
{
name: "hex package",
typ: ftypes.Hex,
Expand Down

0 comments on commit 3ab655e

Please sign in to comment.