Merge pull request #1703 from strk/resolve_relative_gogs_avatars
Fix resolution of relative avatar urls for Gogs published in subpath
This commit is contained in:
commit
6bfc7924bb
2 changed files with 23 additions and 11 deletions
|
@ -120,15 +120,23 @@ func fixMalformedAvatar(url string) string {
|
|||
}
|
||||
|
||||
// expandAvatar is a helper function that converts a relative avatar URL to the
|
||||
// abosolute url.
|
||||
// absolute url.
|
||||
func expandAvatar(repo, rawurl string) string {
|
||||
if !strings.HasPrefix(rawurl, "/avatars/") {
|
||||
return rawurl
|
||||
}
|
||||
url, err := url.Parse(repo)
|
||||
aurl, err := url.Parse(rawurl)
|
||||
if err != nil {
|
||||
return rawurl
|
||||
}
|
||||
url.Path = rawurl
|
||||
return url.String()
|
||||
if aurl.IsAbs() {
|
||||
// Url is already absolute
|
||||
return aurl.String()
|
||||
}
|
||||
|
||||
// Resolve to base
|
||||
burl, err := url.Parse(repo)
|
||||
if err != nil {
|
||||
return rawurl
|
||||
}
|
||||
aurl = burl.ResolveReference(aurl)
|
||||
|
||||
return aurl.String()
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func Test_parse(t *testing.T) {
|
|||
g.Assert(build.Link).Equal(hook.Compare)
|
||||
g.Assert(build.Branch).Equal("master")
|
||||
g.Assert(build.Message).Equal(hook.Commits[0].Message)
|
||||
g.Assert(build.Avatar).Equal("//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
g.Assert(build.Author).Equal(hook.Sender.Login)
|
||||
|
||||
})
|
||||
|
@ -92,7 +92,7 @@ func Test_parse(t *testing.T) {
|
|||
FullName: "gophers/hello-world",
|
||||
Owner: gogs.User{
|
||||
UserName: "gordon",
|
||||
AvatarUrl: "//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
AvatarUrl: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
CloneUrl: "http://gogs.golang.org/gophers/hello-world.git",
|
||||
HtmlUrl: "http://gogs.golang.org/gophers/hello-world",
|
||||
|
@ -114,7 +114,7 @@ func Test_parse(t *testing.T) {
|
|||
FullName: "gophers/hello-world",
|
||||
Owner: gogs.User{
|
||||
UserName: "gordon",
|
||||
AvatarUrl: "//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
AvatarUrl: "http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
}
|
||||
repo := toRepoLite(&from)
|
||||
|
@ -165,7 +165,11 @@ func Test_parse(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
"//1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
"http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87",
|
||||
},
|
||||
{
|
||||
"/gogs/avatars/2",
|
||||
"http://gogs.io/gogs/avatars/2",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue