-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
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") |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
another example where not-escaping |
Has the anchor community looked into merging this code? |
Signed-off-by: Tieg Zaharia <tieg@tidelift.com>
b9d97ca
to
9bd4a32
Compare
I'll work on getting CI passing -- thanks for the fix! 🙌 |
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
There was a problem hiding this 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!
Currently this library is generating PURLs like
pkg:golang/github.com/azure/azure-sdk-for-go@v56.3.0+incompatible
.The PURL spec says that versions should be a "percent-encoded string", and while the
for application/x-www-form-urlencoded content, the original RFC3986 spec for general URIs does not mention using
.
+
character is fine to use while escaping+
to escapeI think it's preferable to escape
, resulting in invalid PURL versions as in
+
because downstream parsers of the URL will likely unescape the+
aspkg:golang/github.com/azure/azure-sdk-for-go@v56.3.0 incompatible
.There's a good analysis of this problem in package-url/purl-spec#261 as well.