summaryrefslogtreecommitdiffstats
path: root/routers/user
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-04-13 01:57:12 +0100
committerGitHub <noreply@github.com>2021-04-12 20:57:12 -0400
commit27f9bda769401626f78dc3ee1c4ebedab6550ca8 (patch)
tree8ad40ddd7f7ccbcfd03c6f37f9c2822203b7ff39 /routers/user
parent51313fbb633c8d2fd710e7a44acdd3a77f1ae32c (diff)
downloadgitea-27f9bda769401626f78dc3ee1c4ebedab6550ca8.tar.gz
gitea-27f9bda769401626f78dc3ee1c4ebedab6550ca8.zip
Prevent NPE on avatar direct rendering if federated avatars disabled (#15434)
#13649 assumed that direct avatar urls would always be libravatar urls - this leads to NPEs if federated avatar service is disabled. Fix #15421 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'routers/user')
-rw-r--r--routers/user/avatar.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/routers/user/avatar.go b/routers/user/avatar.go
index c3ece49089..4287589d1a 100644
--- a/routers/user/avatar.go
+++ b/routers/user/avatar.go
@@ -7,12 +7,14 @@ package user
import (
"errors"
"net/url"
+ "path"
"strconv"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
)
// Avatar redirect browser to user avatar of requested size
@@ -70,8 +72,21 @@ func AvatarByEmailHash(ctx *context.Context) {
}
var avatarURL *url.URL
- avatarURL, err = models.LibravatarURL(email)
- if err != nil {
+
+ if setting.EnableFederatedAvatar && setting.LibravatarService != nil {
+ avatarURL, err = models.LibravatarURL(email)
+ if err != nil {
+ avatarURL, err = url.Parse(models.DefaultAvatarLink())
+ if err != nil {
+ ctx.ServerError("invalid default avatar url", err)
+ return
+ }
+ }
+ } else if !setting.DisableGravatar {
+ copyOfGravatarSourceURL := *setting.GravatarSourceURL
+ avatarURL = &copyOfGravatarSourceURL
+ avatarURL.Path = path.Join(avatarURL.Path, hash)
+ } else {
avatarURL, err = url.Parse(models.DefaultAvatarLink())
if err != nil {
ctx.ServerError("invalid default avatar url", err)