|
|
|
|
@ -120,8 +120,8 @@ func TestRender_CrossReferences(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
"gogits/gogs#12345",
|
|
|
|
|
`<p><a href="`+util.URLJoin(markup.TestAppURL, "gogits", "gogs", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogits/gogs#12345</a></p>`)
|
|
|
|
|
"test-owner/test-repo#12345",
|
|
|
|
|
`<p><a href="`+util.URLJoin(markup.TestAppURL, "test-owner", "test-repo", "issues", "12345")+`" class="ref-issue" rel="nofollow">test-owner/test-repo#12345</a></p>`)
|
|
|
|
|
test(
|
|
|
|
|
"go-gitea/gitea#12345",
|
|
|
|
|
`<p><a href="`+util.URLJoin(markup.TestAppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
|
|
|
|
|
@ -530,43 +530,31 @@ func TestRender_ShortLinks(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRender_RelativeImages(t *testing.T) {
|
|
|
|
|
setting.AppURL = markup.TestAppURL
|
|
|
|
|
|
|
|
|
|
test := func(input, expected, expectedWiki string) {
|
|
|
|
|
render := func(input string, isWiki bool, links markup.Links) string {
|
|
|
|
|
buffer, err := markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: markup.TestRepoURL,
|
|
|
|
|
BranchPath: "master",
|
|
|
|
|
},
|
|
|
|
|
Metas: localMetas,
|
|
|
|
|
}, input)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
|
|
|
|
|
buffer, err = markdown.RenderString(&markup.RenderContext{
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: markup.Links{
|
|
|
|
|
Base: markup.TestRepoURL,
|
|
|
|
|
},
|
|
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
|
Links: links,
|
|
|
|
|
Metas: localMetas,
|
|
|
|
|
IsWiki: true,
|
|
|
|
|
IsWiki: isWiki,
|
|
|
|
|
}, input)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer)))
|
|
|
|
|
return strings.TrimSpace(string(buffer))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rawwiki := util.URLJoin(markup.TestRepoURL, "wiki", "raw")
|
|
|
|
|
mediatree := util.URLJoin(markup.TestRepoURL, "media", "master")
|
|
|
|
|
out := render(`<img src="LINK">`, false, markup.Links{Base: "/test-owner/test-repo"})
|
|
|
|
|
assert.Equal(t, `<a href="/test-owner/test-repo/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/LINK"/></a>`, out)
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
`<img src="Link">`,
|
|
|
|
|
`<img src="`+util.URLJoin(mediatree, "Link")+`"/>`,
|
|
|
|
|
`<img src="`+util.URLJoin(rawwiki, "Link")+`"/>`)
|
|
|
|
|
out = render(`<img src="LINK">`, true, markup.Links{Base: "/test-owner/test-repo"})
|
|
|
|
|
assert.Equal(t, `<a href="/test-owner/test-repo/wiki/raw/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/wiki/raw/LINK"/></a>`, out)
|
|
|
|
|
|
|
|
|
|
test(
|
|
|
|
|
`<img src="./icon.png">`,
|
|
|
|
|
`<img src="`+util.URLJoin(mediatree, "icon.png")+`"/>`,
|
|
|
|
|
`<img src="`+util.URLJoin(rawwiki, "icon.png")+`"/>`)
|
|
|
|
|
out = render(`<img src="LINK">`, false, markup.Links{Base: "/test-owner/test-repo", BranchPath: "test-branch"})
|
|
|
|
|
assert.Equal(t, `<a href="/test-owner/test-repo/media/test-branch/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/media/test-branch/LINK"/></a>`, out)
|
|
|
|
|
|
|
|
|
|
out = render(`<img src="LINK">`, true, markup.Links{Base: "/test-owner/test-repo", BranchPath: "test-branch"})
|
|
|
|
|
assert.Equal(t, `<a href="/test-owner/test-repo/wiki/raw/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/wiki/raw/LINK"/></a>`, out)
|
|
|
|
|
|
|
|
|
|
out = render(`<img src="/LINK">`, true, markup.Links{Base: "/test-owner/test-repo", BranchPath: "test-branch"})
|
|
|
|
|
assert.Equal(t, `<img src="/LINK"/>`, out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ParseClusterFuzz(t *testing.T) {
|
|
|
|
|
@ -719,5 +707,6 @@ func TestIssue18471(t *testing.T) {
|
|
|
|
|
func TestIsFullURL(t *testing.T) {
|
|
|
|
|
assert.True(t, markup.IsFullURLString("https://example.com"))
|
|
|
|
|
assert.True(t, markup.IsFullURLString("mailto:test@example.com"))
|
|
|
|
|
assert.True(t, markup.IsFullURLString("data:image/11111"))
|
|
|
|
|
assert.False(t, markup.IsFullURLString("/foo:bar"))
|
|
|
|
|
}
|
|
|
|
|
|