summaryrefslogtreecommitdiffstats
path: root/modules/markup/markdown
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2024-01-25 09:54:44 +0100
committerGitHub <noreply@github.com>2024-01-25 09:54:44 +0100
commitc46316f7aec1a00b3db74a3565008c44c0b0807f (patch)
tree744161ced60a09c54a2be4d77dcd9c194dc580fb /modules/markup/markdown
parenteaab89c46b77902b70bb8da2f1643a7f909daf45 (diff)
downloadgitea-c46316f7aec1a00b3db74a3565008c44c0b0807f.tar.gz
gitea-c46316f7aec1a00b3db74a3565008c44c0b0807f.zip
Respect branch info for relative links (#28909)
Fix #28904 Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules/markup/markdown')
-rw-r--r--modules/markup/markdown/goldmark.go2
-rw-r--r--modules/markup/markdown/markdown_test.go4
2 files changed, 4 insertions, 2 deletions
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go
index b92b90561b..1db3cbad7e 100644
--- a/modules/markup/markdown/goldmark.go
+++ b/modules/markup/markdown/goldmark.go
@@ -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
}
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 957d773acd..1edfb3e664 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -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/>