Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ func pathEscape(s string) string {
switch {
case c == '@':
t.WriteString("%40")
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

case c == '?' || c == '#' || c == ' ' || c > unicode.MaxASCII:
t.WriteString(url.PathEscape(string(c)))
default:
Expand Down
4 changes: 2 additions & 2 deletions packageurl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ func TestEncoding(t *testing.T) {
},
{
name: "pre-encoded version is unchanged",
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

},
{
name: "unencoded qualifier value is encoded",
Expand Down