]> source.dussan.org Git - gitea.git/commitdiff
Respect branch info for relative links (#28909)
authorKN4CK3R <admin@oldschoolhack.me>
Thu, 25 Jan 2024 08:54:44 +0000 (09:54 +0100)
committerGitHub <noreply@github.com>
Thu, 25 Jan 2024 08:54:44 +0000 (09:54 +0100)
Fix #28904

Co-authored-by: Giteabot <teabot@gitea.io>
modules/markup/markdown/goldmark.go
modules/markup/markdown/markdown_test.go

index b92b90561b990bf8f434d37e463fee9fa61f4d06..1db3cbad7e1b021132ac406ae1c8f174ec40fb6b 100644 (file)
@@ -137,6 +137,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
                                var base string
                                if ctx.IsWiki {
                                        base = ctx.Links.WikiLink()
+                               } else if ctx.Links.HasBranchInfo() {
+                                       base = ctx.Links.SrcLink()
                                } else {
                                        base = ctx.Links.Base
                                }
index 957d773acde18ccda7231c277cae517667e93867..1edfb3e664463f2b200084afad2f229fc58f77d0 100644 (file)
@@ -765,7 +765,7 @@ space</p>
                        Expected: `<p>space @mention-user<br/>
 /just/a/path.bin<br/>
 <a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
-<a href="/user/repo/file.bin" rel="nofollow">local link</a><br/>
+<a href="/user/repo/src/branch/main/file.bin" rel="nofollow">local link</a><br/>
 <a href="https://example.com" rel="nofollow">remote link</a><br/>
 <a href="/user/repo/src/branch/main/file.bin" rel="nofollow">local link</a><br/>
 <a href="https://example.com" rel="nofollow">remote link</a><br/>
@@ -878,7 +878,7 @@ space</p>
                        Expected: `<p>space @mention-user<br/>
 /just/a/path.bin<br/>
 <a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a><br/>
-<a href="/user/repo/file.bin" rel="nofollow">local link</a><br/>
+<a href="/user/repo/src/branch/main/sub/folder/file.bin" rel="nofollow">local link</a><br/>
 <a href="https://example.com" rel="nofollow">remote link</a><br/>
 <a href="/user/repo/src/branch/main/sub/folder/file.bin" rel="nofollow">local link</a><br/>
 <a href="https://example.com" rel="nofollow">remote link</a><br/>