diff options
author | Giteabot <teabot@gitea.io> | 2024-06-04 21:26:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-04 13:26:55 +0000 |
commit | 5136c879c29fdd713f664c68e6d61d4197b6fec0 (patch) | |
tree | ed1a829237a42e6c4ab9e9adc41abe452daf76f2 /modules/markup/html_test.go | |
parent | ca414a7ccf5e26272662e360c44ac50221a0f2d4 (diff) | |
download | gitea-5136c879c29fdd713f664c68e6d61d4197b6fec0.tar.gz gitea-5136c879c29fdd713f664c68e6d61d4197b6fec0.zip |
Make pasted "img" tag has the same behavior as markdown image (#31235) (#31243)
Backport #31235 by wxiaoguang
Fix #31230
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/markup/html_test.go')
-rw-r--r-- | modules/markup/html_test.go | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 6b3bcd7257..a0642bcfa4 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -53,7 +53,7 @@ func TestRender_Commits(t *testing.T) { } sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d" - repo := markup.TestRepoURL + repo := "http://localhost:3000/gogits/gogs" commit := util.URLJoin(repo, "commit", sha) tree := util.URLJoin(repo, "tree", sha, "src") @@ -107,8 +107,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>`) @@ -517,43 +517,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) { @@ -706,5 +694,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")) } |