aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-01-25 17:40:29 +0800
committerGitHub <noreply@github.com>2024-01-25 10:40:29 +0100
commit8766f65addcce5fcfafc915edc3d299f7e2b96fa (patch)
tree81d2233188fab3011f0cbf2a0458d165a5a42846 /modules
parente95006848efedb74ee489bd8335fee5c78fef5ea (diff)
downloadgitea-8766f65addcce5fcfafc915edc3d299f7e2b96fa.tar.gz
gitea-8766f65addcce5fcfafc915edc3d299f7e2b96fa.zip
Respect branch info for relative links (#28909) (#28922)
Backport #28909 by @KN4CK3R Fix #28904 Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Diffstat (limited to 'modules')
-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 6f2bbae6e0..5216d1973c 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/>