From c680eb2cc74823f017f5ad5a4c9e8094cde311f4 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 10 Apr 2021 17:26:28 +0100 Subject: [PATCH] Links in markdown should be absolute to the repository not the server (#15088) * Links in markdown should be absolute to the repository not the server Fix #15075 Signed-off-by: Andrew Thornton * match github Signed-off-by: Andrew Thornton * add testcase Signed-off-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> --- modules/markup/markdown/goldmark.go | 3 ++- modules/markup/markdown/markdown_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go index 07e2e36e1d..ad77177db4 100644 --- a/modules/markup/markdown/goldmark.go +++ b/modules/markup/markdown/goldmark.go @@ -98,7 +98,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa } prefix = strings.Replace(prefix, "/src/", "/media/", 1) - lnk := string(link) + lnk := strings.TrimLeft(string(link), "/") + lnk = giteautil.URLJoin(prefix, lnk) link = []byte(lnk) } diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 5b3ef21fb6..0e340763ae 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -93,6 +93,19 @@ func TestRender_Images(t *testing.T) { test( "[!["+title+"]("+url+")]("+href+")", `

`+title+`

`) + + url = "/../../.images/src/02/train.jpg" + test( + "!["+title+"]("+url+")", + `

`+title+`

`) + + test( + "[["+title+"|"+url+"]]", + `

`+title+`

`) + test( + "[!["+title+"]("+url+")]("+href+")", + `

`+title+`

`) + } func testAnswers(baseURLContent, baseURLImages string) []string {