loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

authored by

Gusted and committed by
GitHub
257b7171 d1f55840

+4 -5
+4 -5
models/repo_avatar.go
··· 108 108 // avatarLink returns user avatar absolute link. 109 109 func (repo *Repository) avatarLink(e db.Engine) string { 110 110 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:] 116 114 } 115 + // otherwise, return the link as it is 117 116 return link 118 117 } 119 118