-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make pasted "img" tag has the same behavior as markdown image (#31235) (
#31243) Backport #31235 by wxiaoguang Fix #31230 --------- Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
- Loading branch information
1 parent
ca414a7
commit 5136c87
Showing
5 changed files
with
80 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[email protected]")) | ||
assert.True(t, markup.IsFullURLString("data:image/11111")) | ||
assert.False(t, markup.IsFullURLString("/foo:bar")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters