Fix missing UnescapePath for a token

This commit is contained in:
Ingo Oppermann 2023-08-03 09:40:56 +03:00
parent dc11d33a97
commit 90974fed30
No known key found for this signature in database
GPG Key ID: 2AB32426E9DD229E
3 changed files with 18 additions and 1 deletions

View File

@ -30,7 +30,9 @@ func TestUnmarshal(t *testing.T) {
{":xxx", "", "xxx"},
{"foo:xxx", "foo", "xxx"},
{"foo::bar:xxx", "foo:bar", "xxx"},
{"foo:::bar:xxx", "foo:", "bar:xxx"},
{"foo::::bar:xxx", "foo::bar", "xxx"},
{"foo-bar:%26%21%27", "foo-bar", "%26%21%27"},
}
for _, d := range data {

View File

@ -220,8 +220,21 @@ func GetToken(u *url.URL) (string, string) {
return u.Path, ""
}
rawPath := "/" + strings.Join(pathElements[:nPathElements-1], "/")
rawToken := pathElements[nPathElements-1]
path, err := url.PathUnescape(rawPath)
if err != nil {
path = rawPath
}
token, err := url.PathUnescape(rawToken)
if err != nil {
token = rawToken
}
// Return the path without the token
return "/" + strings.Join(pathElements[:nPathElements-1], "/"), pathElements[nPathElements-1]
return path, token
}
func splitPath(path string) []string {

View File

@ -12,6 +12,8 @@ func TestToken(t *testing.T) {
{"/foo/bar", "/foo", "bar"},
{"/foo/bar?token=abc", "/foo/bar", "abc"},
{"/foo/bar/abc", "/foo/bar", "abc"},
{"/foo/bar/&!'", "/foo/bar", "&!'"},
{"/foo/bar/%26%21%27", "/foo/bar", "&!'"},
}
for _, d := range data {