summaryrefslogtreecommitdiffstats
path: root/modules/markup/html_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markup/html_test.go')
-rw-r--r--modules/markup/html_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 85418892ef..a494c5bd18 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -425,6 +425,41 @@ func TestRender_ShortLinks(t *testing.T) {
`<p><a href="https://example.org" rel="nofollow">[[foobar]]</a></p>`)
}
+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, err := markdown.RenderString(&RenderContext{
+ URLPrefix: tree,
+ Metas: localMetas,
+ }, input)
+ assert.NoError(t, err)
+ assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
+ buffer, err = markdown.RenderString(&RenderContext{
+ URLPrefix: setting.AppSubURL,
+ Metas: localMetas,
+ IsWiki: true,
+ }, input)
+ assert.NoError(t, err)
+ assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
+ }
+
+ rawwiki := util.URLJoin(AppSubURL, "wiki", "raw")
+ mediatree := util.URLJoin(AppSubURL, "media", "master")
+
+ test(
+ `<img src="Link">`,
+ `<img src="`+util.URLJoin(mediatree, "Link")+`"/>`,
+ `<img src="`+util.URLJoin(rawwiki, "Link")+`"/>`)
+
+ test(
+ `<img src="./icon.png">`,
+ `<img src="`+util.URLJoin(mediatree, "icon.png")+`"/>`,
+ `<img src="`+util.URLJoin(rawwiki, "icon.png")+`"/>`)
+}
+
func Test_ParseClusterFuzz(t *testing.T) {
setting.AppURL = AppURL
setting.AppSubURL = AppSubURL