@@ -53,7 +53,7 @@ func TestRender_Commits(t *testing.T) {
5353 }
5454
5555 sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
56- repo := markup . TestRepoURL
56+ repo := "http://localhost:3000/gogits/gogs"
5757 commit := util .URLJoin (repo , "commit" , sha )
5858 tree := util .URLJoin (repo , "tree" , sha , "src" )
5959
@@ -107,8 +107,8 @@ func TestRender_CrossReferences(t *testing.T) {
107107 }
108108
109109 test (
110- "gogits/gogs #12345" ,
111- `<p><a href="` + util .URLJoin (markup .TestAppURL , "gogits " , "gogs " , "issues" , "12345" )+ `" class="ref-issue" rel="nofollow">gogits/gogs #12345</a></p>` )
110+ "test-owner/test-repo #12345" ,
111+ `<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>` )
112112 test (
113113 "go-gitea/gitea#12345" ,
114114 `<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) {
517517}
518518
519519func TestRender_RelativeImages (t * testing.T ) {
520- setting .AppURL = markup .TestAppURL
521-
522- test := func (input , expected , expectedWiki string ) {
520+ render := func (input string , isWiki bool , links markup.Links ) string {
523521 buffer , err := markdown .RenderString (& markup.RenderContext {
524- Ctx : git .DefaultContext ,
525- Links : markup.Links {
526- Base : markup .TestRepoURL ,
527- BranchPath : "master" ,
528- },
529- Metas : localMetas ,
530- }, input )
531- assert .NoError (t , err )
532- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (buffer )))
533- buffer , err = markdown .RenderString (& markup.RenderContext {
534- Ctx : git .DefaultContext ,
535- Links : markup.Links {
536- Base : markup .TestRepoURL ,
537- },
522+ Ctx : git .DefaultContext ,
523+ Links : links ,
538524 Metas : localMetas ,
539- IsWiki : true ,
525+ IsWiki : isWiki ,
540526 }, input )
541527 assert .NoError (t , err )
542- assert . Equal ( t , strings .TrimSpace (expectedWiki ), strings . TrimSpace ( string (buffer ) ))
528+ return strings .TrimSpace (string (buffer ))
543529 }
544530
545- rawwiki := util . URLJoin ( markup . TestRepoURL , "wiki" , "raw" )
546- mediatree := util . URLJoin ( markup . TestRepoURL , "media" , "master" )
531+ out := render ( `<img src="LINK">` , false , markup. Links { Base : "/test-owner/test-repo" } )
532+ assert . Equal ( t , `<a href="/test-owner/test-repo/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/LINK"/></a>` , out )
547533
548- test (
549- `<img src="Link">` ,
550- `<img src="` + util .URLJoin (mediatree , "Link" )+ `"/>` ,
551- `<img src="` + util .URLJoin (rawwiki , "Link" )+ `"/>` )
534+ out = render (`<img src="LINK">` , true , markup.Links {Base : "/test-owner/test-repo" })
535+ 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 )
552536
553- test (
554- `<img src="./icon.png">` ,
555- `<img src="` + util .URLJoin (mediatree , "icon.png" )+ `"/>` ,
556- `<img src="` + util .URLJoin (rawwiki , "icon.png" )+ `"/>` )
537+ out = render (`<img src="LINK">` , false , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
538+ 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 )
539+
540+ out = render (`<img src="LINK">` , true , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
541+ 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 )
542+
543+ out = render (`<img src="/LINK">` , true , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
544+ assert .Equal (t , `<img src="/LINK"/>` , out )
557545}
558546
559547func Test_ParseClusterFuzz (t * testing.T ) {
@@ -706,5 +694,6 @@ func TestIssue18471(t *testing.T) {
706694func TestIsFullURL (t * testing.T ) {
707695 assert .True (t , markup .IsFullURLString ("https://example.com" ))
708696 assert .True (t , markup .IsFullURLString ("mailto:test@example.com" ))
697+ assert .True (t , markup .IsFullURLString ("data:image/11111" ))
709698 assert .False (t , markup .IsFullURLString ("/foo:bar" ))
710699}
0 commit comments