Skip to content

Commit

Permalink
Encode "+" as "%2B" since "+" is a valid SemVer character.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiegz committed Jan 23, 2024
1 parent 4d3a8fa commit b9d97ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,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")
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",
},
{
name: "unencoded qualifier value is encoded",
Expand Down

0 comments on commit b9d97ca

Please sign in to comment.