diff --git a/modules/markup/html.go b/modules/markup/html.go index 216a1f20a..7b9844bf7 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -401,7 +401,7 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) { } case html.ElementNode: if node.Data == "img" { - for _, attr := range node.Attr { + for i, attr := range node.Attr { if attr.Key != "src" { continue } @@ -414,6 +414,7 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) { attr.Val = util.URLJoin(prefix, attr.Val) } + node.Attr[i] = attr } } else if node.Data == "a" { visitText = false diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 4d6344a72..dddb3ade0 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -384,6 +384,32 @@ func TestRender_ShortLinks(t *testing.T) { `
`) } +func TestRender_RelativeImages(t *testing.T) { + setting.AppURL = AppURL + setting.AppSubURL = AppSubURL + tree := util.URLJoin(AppSubURL, "src", "master") + + test := func(input, expected, expectedWiki string) { + buffer := markdown.RenderString(input, tree, localMetas) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) + buffer = markdown.RenderWiki([]byte(input), setting.AppSubURL, localMetas) + assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer)) + } + + rawwiki := util.URLJoin(AppSubURL, "wiki", "raw") + mediatree := util.URLJoin(AppSubURL, "media", "master") + + test( + ``, + ``, + ``) + + test( + ``, + ``, + ``) +} + func Test_ParseClusterFuzz(t *testing.T) { setting.AppURL = AppURL setting.AppSubURL = AppSubURL