diff --git a/src/packageurl/__init__.py b/src/packageurl/__init__.py index a33c457..b6d8a3f 100644 --- a/src/packageurl/__init__.py +++ b/src/packageurl/__init__.py @@ -532,10 +532,7 @@ def from_string(cls, purl: str) -> "PackageURL": ns_name_parts = ns_name.split("/") ns_name_parts = [seg for seg in ns_name_parts if seg and seg.strip()] name = "" - if type == "golang": - name = "/".join(ns_name_parts) - namespace = "" - elif not namespace and len(ns_name_parts) > 1: + if not namespace and len(ns_name_parts) > 1: name = ns_name_parts[-1] ns = ns_name_parts[0:-1] namespace = "/".join(ns) diff --git a/src/packageurl/contrib/purl2url.py b/src/packageurl/contrib/purl2url.py index 2d1bfd1..bbe14e6 100644 --- a/src/packageurl/contrib/purl2url.py +++ b/src/packageurl/contrib/purl2url.py @@ -264,13 +264,14 @@ def build_golang_repo_url(purl): """ purl_data = PackageURL.from_string(purl) + namespace = purl_data.namespace name = purl_data.name version = purl_data.version if name and version: - return f"https://pkg.go.dev/{name}@{version}" + return f"https://pkg.go.dev/{namespace}/{name}@{version}" elif name: - return f"https://pkg.go.dev/{name}" + return f"https://pkg.go.dev/{namespace}/{name}" # Download URLs: diff --git a/tests/data/test-suite-data.json b/tests/data/test-suite-data.json index e0b8661..aee685c 100644 --- a/tests/data/test-suite-data.json +++ b/tests/data/test-suite-data.json @@ -28,8 +28,8 @@ "purl": "pkg:GOLANG/google.golang.org/genproto#/googleapis/api/annotations/", "canonical_purl": "pkg:golang/google.golang.org/genproto#googleapis/api/annotations", "type": "golang", - "namespace": null, - "name": "google.golang.org/genproto", + "namespace": "google.golang.org", + "name": "genproto", "version": null, "qualifiers": null, "subpath": "googleapis/api/annotations", @@ -40,8 +40,8 @@ "purl": "pkg:GOLANG/google.golang.org/genproto@abcdedf#/googleapis/api/annotations/", "canonical_purl": "pkg:golang/google.golang.org/genproto@abcdedf#googleapis/api/annotations", "type": "golang", - "namespace": null, - "name": "google.golang.org/genproto", + "namespace": "google.golang.org", + "name": "genproto", "version": "abcdedf", "qualifiers": null, "subpath": "googleapis/api/annotations", @@ -52,8 +52,8 @@ "purl": "pkg:golang/github.com/nats-io/nats-server/v2/server@v1.2.9", "canonical_purl": "pkg:golang/github.com/nats-io/nats-server/v2/server@v1.2.9", "type": "golang", - "namespace": null, - "name": "github.com/nats-io/nats-server/v2/server", + "namespace": "github.com/nats-io/nats-server/v2/", + "name": "server", "version": "v1.2.9", "qualifiers": null, "subpath": null,