fix corner case with double-slash in Gogs sender. see #1263
This commit is contained in:
parent
c68d1232e2
commit
e1daf0fd74
2 changed files with 28 additions and 5 deletions
|
@ -110,6 +110,10 @@ func fixMalformedAvatar(url string) string {
|
|||
if index != -1 {
|
||||
return url[index+1:]
|
||||
}
|
||||
index = strings.Index(url, "//avatars/")
|
||||
if index != -1 {
|
||||
return strings.Replace(url, "//avatars/", "/avatars/", -1)
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
|
|
|
@ -114,13 +114,32 @@ func Test_parse(t *testing.T) {
|
|||
})
|
||||
|
||||
g.It("Should correct a malformed avatar url", func() {
|
||||
var urls = []string{
|
||||
"http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
|
||||
var urls = []struct {
|
||||
Before string
|
||||
After string
|
||||
}{
|
||||
{
|
||||
"http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
{
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
{
|
||||
"http://gogs.golang.org/avatars/1",
|
||||
"http://gogs.golang.org/avatars/1",
|
||||
},
|
||||
{
|
||||
"http://gogs.golang.org//avatars/1",
|
||||
"http://gogs.golang.org/avatars/1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, url := range urls {
|
||||
url = fixMalformedAvatar(url)
|
||||
g.Assert(url).Equal("//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
got := fixMalformedAvatar(url.Before)
|
||||
g.Assert(got).Equal(url.After)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue