fix corner case with double-slash in Gogs sender. see #1263

This commit is contained in:
Brad Rydzewski 2015-10-27 18:44:41 -07:00
parent c68d1232e2
commit e1daf0fd74
2 changed files with 28 additions and 5 deletions

View file

@ -110,6 +110,10 @@ func fixMalformedAvatar(url string) string {
if index != -1 { if index != -1 {
return url[index+1:] return url[index+1:]
} }
index = strings.Index(url, "//avatars/")
if index != -1 {
return strings.Replace(url, "//avatars/", "/avatars/", -1)
}
return url return url
} }

View file

@ -114,13 +114,32 @@ func Test_parse(t *testing.T) {
}) })
g.It("Should correct a malformed avatar url", func() { g.It("Should correct a malformed avatar url", func() {
var urls = []string{
"http://gogs.golang.org///1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", var urls = []struct {
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87", 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 { for _, url := range urls {
url = fixMalformedAvatar(url) got := fixMalformedAvatar(url.Before)
g.Assert(url).Equal("//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87") g.Assert(got).Equal(url.After)
} }
}) })