Skip to content

Commit

Permalink
Encode "+" as "%2B" since "+" is a valid SemVer character. (#17)
Browse files Browse the repository at this point in the history
Signed-off-by: Tieg Zaharia <[email protected]>
Signed-off-by: Alex Goodman <[email protected]>
Co-authored-by: Alex Goodman <[email protected]>
  • Loading branch information
tiegz and wagoodman authored Mar 12, 2024
1 parent 89ca48f commit 8b9478f
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 @@ -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")
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 8b9478f

Please sign in to comment.