Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode "+" as "%2B" since "+" is a valid SemVer character. #17

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

tiegz
Copy link

@tiegz tiegz commented Jan 23, 2024

Currently this library is generating PURLs like pkg:golang/github.com/azure/[email protected]+incompatible.

The PURL spec says that versions should be a "percent-encoded string", and while the + character is fine to use while escaping for application/x-www-form-urlencoded content, the original RFC3986 spec for general URIs does not mention using + to escape .

I think it's preferable to escape + because downstream parsers of the URL will likely unescape the + as , resulting in invalid PURL versions as in pkg:golang/github.com/azure/[email protected] incompatible.

There's a good analysis of this problem in package-url/purl-spec#261 as well.

case c == '+':
// url.PathEscape doesn't encode '+' since it's a valid query escape character for ' ' in application/x-www-form-urlencoded, but '+' is a
// valid character in semver so we don't want it to be unintentionally unescaped as ' ' by downstream parsers of the purl.
t.WriteString("%2B")
Copy link
Author

@tiegz tiegz Jan 23, 2024

Choose a reason for hiding this comment

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

note that url.QueryEscape will encode +, but that method was replaced with PathEscape in #1

input: "pkg:type/name/space/name@versio%20n?key=value#sub/path",
expected: "pkg:type/name/space/name@versio%20n?key=value#sub/path",
input: "pkg:type/name/space/name@versio%20n%2Bbeta?key=value#sub/path",
expected: "pkg:type/name/space/name@versio%20n%2Bbeta?key=value#sub/path",
Copy link
Author

Choose a reason for hiding this comment

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

before the fix in this PR, this test would fail as:

packageurl_test.go:389: expected pkg:type/name/space/name@versio%20n%2Bbeta?key=value#sub/path to parse as pkg:type/name/space/name@versio%20n%2Bbeta?key=value#sub/path but got pkg:type/name/space/name@versio%20n+beta?key=value#sub/path

@tiegz
Copy link
Author

tiegz commented Jan 29, 2024

another example where not-escaping + is undesirable: "pkg:rpm/rhel/[email protected]". Downstream Purl libraries will likely interpret that package name as "libstdc "

@RicardoAReyes
Copy link

Has the anchor community looked into merging this code?

@wagoodman
Copy link

I'll work on getting CI passing -- thanks for the fix! 🙌

@wagoodman wagoodman self-assigned this Mar 12, 2024
Copy link

@wagoodman wagoodman left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@wagoodman wagoodman merged commit 8b9478f into anchore:master Mar 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants