diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index 4e06e70c..bc698c04 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -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 } diff --git a/remote/gogs/helper_test.go b/remote/gogs/helper_test.go index ba38c49b..444596e5 100644 --- a/remote/gogs/helper_test.go +++ b/remote/gogs/helper_test.go @@ -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) } })