@@ -120,8 +120,8 @@ func TestRender_CrossReferences(t *testing.T) {
120120 }
121121
122122 test (
123- "gogits/gogs #12345" ,
124- `<p><a href="` + util .URLJoin (markup .TestAppURL , "gogits " , "gogs " , "issues" , "12345" )+ `" class="ref-issue" rel="nofollow">gogits/gogs #12345</a></p>` )
123+ "test-owner/test-repo #12345" ,
124+ `<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>` )
125125 test (
126126 "go-gitea/gitea#12345" ,
127127 `<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) {
530530}
531531
532532func TestRender_RelativeImages (t * testing.T ) {
533- setting .AppURL = markup .TestAppURL
534-
535- test := func (input , expected , expectedWiki string ) {
533+ render := func (input string , isWiki bool , links markup.Links ) string {
536534 buffer , err := markdown .RenderString (& markup.RenderContext {
537- Ctx : git .DefaultContext ,
538- Links : markup.Links {
539- Base : markup .TestRepoURL ,
540- BranchPath : "master" ,
541- },
542- Metas : localMetas ,
543- }, input )
544- assert .NoError (t , err )
545- assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (buffer )))
546- buffer , err = markdown .RenderString (& markup.RenderContext {
547- Ctx : git .DefaultContext ,
548- Links : markup.Links {
549- Base : markup .TestRepoURL ,
550- },
535+ Ctx : git .DefaultContext ,
536+ Links : links ,
551537 Metas : localMetas ,
552- IsWiki : true ,
538+ IsWiki : isWiki ,
553539 }, input )
554540 assert .NoError (t , err )
555- assert . Equal ( t , strings .TrimSpace (expectedWiki ), strings . TrimSpace ( string (buffer ) ))
541+ return strings .TrimSpace (string (buffer ))
556542 }
557543
558- rawwiki := util . URLJoin ( markup . TestRepoURL , "wiki" , "raw" )
559- mediatree := util . URLJoin ( markup . TestRepoURL , "media" , "master" )
544+ out := render ( `<img src="LINK">` , false , markup. Links { Base : "/test-owner/test-repo" } )
545+ assert . Equal ( t , `<a href="/test-owner/test-repo/LINK" target="_blank" rel="nofollow noopener"><img src="/test-owner/test-repo/LINK"/></a>` , out )
560546
561- test (
562- `<img src="Link">` ,
563- `<img src="` + util .URLJoin (mediatree , "Link" )+ `"/>` ,
564- `<img src="` + util .URLJoin (rawwiki , "Link" )+ `"/>` )
547+ out = render (`<img src="LINK">` , true , markup.Links {Base : "/test-owner/test-repo" })
548+ 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 )
565549
566- test (
567- `<img src="./icon.png">` ,
568- `<img src="` + util .URLJoin (mediatree , "icon.png" )+ `"/>` ,
569- `<img src="` + util .URLJoin (rawwiki , "icon.png" )+ `"/>` )
550+ out = render (`<img src="LINK">` , false , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
551+ 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 )
552+
553+ out = render (`<img src="LINK">` , true , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
554+ 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 )
555+
556+ out = render (`<img src="/LINK">` , true , markup.Links {Base : "/test-owner/test-repo" , BranchPath : "test-branch" })
557+ assert .Equal (t , `<img src="/LINK"/>` , out )
570558}
571559
572560func Test_ParseClusterFuzz (t * testing.T ) {
@@ -719,5 +707,6 @@ func TestIssue18471(t *testing.T) {
719707func TestIsFullURL (t * testing.T ) {
720708 assert .True (t , markup .IsFullURLString ("https://example.com" ))
721709 assert .
True (
t ,
markup .
IsFullURLString (
"mailto:[email protected] " ))
710+ assert .True (t , markup .IsFullURLString ("data:image/11111" ))
722711 assert .False (t , markup .IsFullURLString ("/foo:bar" ))
723712}
0 commit comments