Skip to content

Handle non-canonical input purls a bit more gracefully#89

Merged
shibumi merged 2 commits intopackage-url:masterfrom
petergardfjall:support-input-version-with-slashes
Mar 6, 2026
Merged

Handle non-canonical input purls a bit more gracefully#89
shibumi merged 2 commits intopackage-url:masterfrom
petergardfjall:support-input-version-with-slashes

Conversation

@petergardfjall
Copy link
Copy Markdown
Collaborator

@petergardfjall petergardfjall commented Feb 27, 2026

This PR makes the library handle some non-canonical input purls a bit more gracefully:

  • Versions that include unescaped slashes such as pkg:github/golang/mod@refs/tags/v0.30.0 is now correctly parsed as pkg:github/golang/mod@refs%2Ftags%2Fv0.30.0.
    • It used to get parsed into pkg:github/golang/mod%40refs/tags/v0.30.0 which makes very little sense. This turned out to be due to not following the purl parse procedure very well so I updated the parsing code to more closely follow that. In particular the parsing of namespace, name and version.
  • Interpret plus characters in input qualifiers literally (instead of parsing them as spaces). This makes a purl like pkg:generic/grafana@12.0.1?checksum=sha256:18a348109d3f92772bee72a55eabb9d318596add6a70b92adb6ff8e789d587a8&download_url=https://dl.grafana.com/enterprise/release/grafana-enterprise-12.0.1+security-01.linux-amd64.tar.gz parse correctly. A space (which should be rare) can (and should) still be escaped with %20 in the input (rather than +).

Test-cases have been added for these cases, which go a bit outside the purl-spec testsuite.

@petergardfjall petergardfjall changed the title handle non-canonical input purls a bit more gracefully Handle non-canonical input purls a bit more gracefully Feb 27, 2026
@petergardfjall petergardfjall force-pushed the support-input-version-with-slashes branch from 9242b46 to d7b880f Compare February 27, 2026 16:53
@petergardfjall petergardfjall force-pushed the support-input-version-with-slashes branch from d7b880f to b99e1b9 Compare March 5, 2026 06:54
Comment thread packageurl.go
Comment on lines +526 to +527
if purlType != TypeNPM && strings.HasPrefix(remainder, "@") {
return "", "", "", fmt.Errorf("purl is missing name")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petergardfjall petergardfjall force-pushed the support-input-version-with-slashes branch from b99e1b9 to 8f9a644 Compare March 5, 2026 07:33
Comment thread packageurl.go
// procedure.
//
// [HOW-TO-PARSE]: https://github.com/package-url/purl-spec/blob/main/docs/how-to-parse.md
func separateNamespaceNameVersion(purlType string, remainder string) (ns, name, version string, err error) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function now follows https://github.com/package-url/purl-spec/blob/5d9516cc661e77a88cf33fadc057d18df963ff3c/docs/how-to-parse.md?plain=1#L52-L76.

With doing that we will start by splitting on @ which then will allow us to correctly parse input like pkg:github/golang/mod@refs/tags/v0.30.0, which we failed to properly parse before.

@shibumi shibumi merged commit 53d197f into package-url:master Mar 6, 2026
2 checks passed
@petergardfjall petergardfjall deleted the support-input-version-with-slashes branch March 7, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants