From b4b8c9679f58a24fb81643b8b4b4c55cf6fb5f0f Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 30 Dec 2019 11:55:51 +0100 Subject: [PATCH] fix 500 error for ghost avatar (#9537) --- routers/user/avatar.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/routers/user/avatar.go b/routers/user/avatar.go index 20597c72f..045206c50 100644 --- a/routers/user/avatar.go +++ b/routers/user/avatar.go @@ -6,6 +6,7 @@ package user import ( "strconv" + "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" @@ -23,14 +24,19 @@ func Avatar(ctx *context.Context) { log.Debug("Asked avatar for user %v and size %v", userName, size) - user, err := models.GetUserByName(userName) - if err != nil { - if models.IsErrUserNotExist(err) { - ctx.ServerError("Requested avatar for invalid user", err) - } else { - ctx.ServerError("Retrieving user by name", err) + var user *models.User + if strings.ToLower(userName) != "ghost" { + user, err = models.GetUserByName(userName) + if err != nil { + if models.IsErrUserNotExist(err) { + ctx.ServerError("Requested avatar for invalid user", err) + } else { + ctx.ServerError("Retrieving user by name", err) + } + return } - return + } else { + user = models.NewGhostUser() } ctx.Redirect(user.RealSizedAvatarLink(size))