Skip to content

Commit ab458ce

Browse files
kemzebwxiaoguang
andauthored
Return an empty string when a repo has no avatar in the repo API (#31187)
Resolves #31167. #30885 changed the behavior of `repo.AvatarLink()` where it can now take the empty string and append it to the app data URL. This does not point to a valid avatar image URL, and, as the issue mentions, previous Gitea versions returned the empty string. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent a427595 commit ab458ce

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

models/repo/avatar.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string {
8484
return setting.AppSubURL + "/repo-avatars/" + url.PathEscape(repo.Avatar)
8585
}
8686

87-
// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
87+
// AvatarLink returns the full avatar url with http host or the empty string if the repo doesn't have an avatar.
88+
//
89+
// TODO: refactor it to a relative URL, but it is still used in API response at the moment
8890
func (repo *Repository) AvatarLink(ctx context.Context) string {
89-
return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx))
91+
relLink := repo.relAvatarLink(ctx)
92+
if relLink != "" {
93+
return httplib.MakeAbsoluteURL(ctx, relLink)
94+
}
95+
return ""
9096
}

0 commit comments

Comments
 (0)