aboutsummaryrefslogtreecommitdiffstats
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.go117
1 files changed, 71 insertions, 46 deletions
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 62fd0f5a85..89ecfc036b 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -42,8 +42,10 @@ func TestRender_Commits(t *testing.T) {
buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: ".md",
- URLPrefix: markup.TestRepoURL,
- Metas: localMetas,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
+ Metas: localMetas,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -93,8 +95,10 @@ func TestRender_CrossReferences(t *testing.T) {
buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: setting.AppSubURL,
- Metas: localMetas,
+ Links: markup.Links{
+ Base: setting.AppSubURL,
+ },
+ Metas: localMetas,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -138,7 +142,9 @@ func TestRender_links(t *testing.T) {
buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: markup.TestRepoURL,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -238,7 +244,9 @@ func TestRender_email(t *testing.T) {
res, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: markup.TestRepoURL,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res))
@@ -309,7 +317,9 @@ func TestRender_emoji(t *testing.T) {
buffer, err := markup.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext,
RelativePath: "a.md",
- URLPrefix: markup.TestRepoURL,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
@@ -371,29 +381,34 @@ func TestRender_ShortLinks(t *testing.T) {
test := func(input, expected, expectedWiki string) {
buffer, err := markdown.RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: tree,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ BranchPath: "master",
+ },
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
buffer, err = markdown.RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: markup.TestRepoURL,
- Metas: localMetas,
- IsWiki: true,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
+ Metas: localMetas,
+ IsWiki: true,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
}
- rawtree := util.URLJoin(markup.TestRepoURL, "raw", "master")
+ mediatree := util.URLJoin(markup.TestRepoURL, "media", "master")
url := util.URLJoin(tree, "Link")
otherURL := util.URLJoin(tree, "Other-Link")
encodedURL := util.URLJoin(tree, "Link%3F")
- imgurl := util.URLJoin(rawtree, "Link.jpg")
- otherImgurl := util.URLJoin(rawtree, "Link+Other.jpg")
- encodedImgurl := util.URLJoin(rawtree, "Link+%23.jpg")
- notencodedImgurl := util.URLJoin(rawtree, "some", "path", "Link+#.jpg")
+ imgurl := util.URLJoin(mediatree, "Link.jpg")
+ otherImgurl := util.URLJoin(mediatree, "Link+Other.jpg")
+ encodedImgurl := util.URLJoin(mediatree, "Link+%23.jpg")
+ notencodedImgurl := util.URLJoin(mediatree, "some", "path", "Link+#.jpg")
urlWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link")
otherURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Other-Link")
encodedURLWiki := util.URLJoin(markup.TestRepoURL, "wiki", "Link%3F")
@@ -475,21 +490,25 @@ func TestRender_ShortLinks(t *testing.T) {
func TestRender_RelativeImages(t *testing.T) {
setting.AppURL = markup.TestAppURL
- tree := util.URLJoin(markup.TestRepoURL, "src", "master")
test := func(input, expected, expectedWiki string) {
buffer, err := markdown.RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: tree,
- Metas: localMetas,
+ 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(buffer))
buffer, err = markdown.RenderString(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: markup.TestRepoURL,
- Metas: localMetas,
- IsWiki: true,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: markup.TestRepoURL,
+ },
+ Metas: localMetas,
+ IsWiki: true,
}, input)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(buffer))
@@ -521,9 +540,11 @@ func Test_ParseClusterFuzz(t *testing.T) {
var res strings.Builder
err := markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: "https://example.com",
+ },
+ Metas: localMetas,
}, strings.NewReader(data), &res)
assert.NoError(t, err)
assert.NotContains(t, res.String(), "<html")
@@ -532,9 +553,11 @@ func Test_ParseClusterFuzz(t *testing.T) {
res.Reset()
err = markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: "https://example.com",
+ },
+ Metas: localMetas,
}, strings.NewReader(data), &res)
assert.NoError(t, err)
@@ -543,6 +566,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
func TestPostProcess_RenderDocument(t *testing.T) {
setting.AppURL = markup.TestAppURL
+ setting.StaticURLPrefix = markup.TestAppURL // can't run standalone
localMetas := map[string]string{
"user": "go-gitea",
@@ -553,9 +577,11 @@ func TestPostProcess_RenderDocument(t *testing.T) {
test := func(input, expected string) {
var res strings.Builder
err := markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: "https://example.com",
+ },
+ Metas: localMetas,
}, strings.NewReader(input), &res)
assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String()))
@@ -594,9 +620,8 @@ func TestIssue16020(t *testing.T) {
var res strings.Builder
err := markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Metas: localMetas,
}, strings.NewReader(data), &res)
assert.NoError(t, err)
assert.Equal(t, data, res.String())
@@ -611,9 +636,8 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
for i := 0; i < b.N; i++ {
var res strings.Builder
err := markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Metas: localMetas,
}, strings.NewReader(data), &res)
assert.NoError(b, err)
}
@@ -622,8 +646,10 @@ func BenchmarkEmojiPostprocess(b *testing.B) {
func TestFuzz(t *testing.T) {
s := "t/l/issues/8#/../../a"
renderContext := markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com/go-gitea/gitea",
+ Ctx: git.DefaultContext,
+ Links: markup.Links{
+ Base: "https://example.com/go-gitea/gitea",
+ },
Metas: map[string]string{
"user": "go-gitea",
"repo": "gitea",
@@ -640,9 +666,8 @@ func TestIssue18471(t *testing.T) {
var res strings.Builder
err := markup.PostProcess(&markup.RenderContext{
- Ctx: git.DefaultContext,
- URLPrefix: "https://example.com",
- Metas: localMetas,
+ Ctx: git.DefaultContext,
+ Metas: localMetas,
}, strings.NewReader(data), &res)
assert.NoError(t, err)