Skip to content

Commit 257b717

Browse files
author
Gusted
authored
Fix possible panic (#17694)
- The code will get the first and second character `link[{0,1]]`. However in a rare case the `link` could have 1 character and thus the `link[1]` will create a panic.
1 parent d1f5584 commit 257b717

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

models/repo_avatar.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ func (repo *Repository) AvatarLink() string {
108108
// avatarLink returns user avatar absolute link.
109109
func (repo *Repository) avatarLink(e db.Engine) string {
110110
link := repo.relAvatarLink(e)
111-
// link may be empty!
112-
if len(link) > 0 {
113-
if link[0] == '/' && link[1] != '/' {
114-
return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL)[1:]
115-
}
111+
// we only prepend our AppURL to our known (relative, internal) avatar link to get an absolute URL
112+
if strings.HasPrefix(link, "/") && !strings.HasPrefix(link, "//") {
113+
return setting.AppURL + strings.TrimPrefix(link, setting.AppSubURL)[1:]
116114
}
115+
// otherwise, return the link as it is
117116
return link
118117
}
119118

0 commit comments

Comments
 (0)