Fix some edge cases; closes #3232

- Fixes wrong usage of AppURL
- Fixes wrong rendering with extra path segments when AppSubURL is empty
- Now also renders all links when 2+ permalinks are present
This commit is contained in:
Mai-Lapyst 2024-04-17 12:44:17 +02:00
parent e4aa7bd511
commit 5b6b3f3fb3
No known key found for this signature in database
GPG key ID: F88D929C09E239F8
3 changed files with 191 additions and 79 deletions

View file

@ -56,11 +56,11 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
urlFull := node.Data[m[0]:m[1]]
// Ensure that we only use links to local repositories
if !strings.HasPrefix(urlFull, setting.AppURL+setting.AppSubURL) {
if !strings.HasPrefix(urlFull, setting.AppURL) {
return nil
}
projPath := strings.TrimSuffix(node.Data[m[2]:m[3]], "/")
projPath := strings.TrimPrefix(strings.TrimSuffix(node.Data[m[0]:m[3]], "/"), setting.AppURL)
commitSha := node.Data[m[4]:m[5]]
filePath := node.Data[m[6]:m[7]]
@ -70,6 +70,10 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
preview.end = m[1]
projPathSegments := strings.Split(projPath, "/")
if len(projPathSegments) != 2 {
return nil
}
ownerName := projPathSegments[len(projPathSegments)-2]
repoName := projPathSegments[len(projPathSegments)-1]