@@ -120,8 +120,8 @@ func TestRender_CrossReferences(t *testing.T) {
120
120
}
121
121
122
122
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>` )
125
125
test (
126
126
"go-gitea/gitea#12345" ,
127
127
`<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) {
530
530
}
531
531
532
532
func 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 {
536
534
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 ,
551
537
Metas : localMetas ,
552
- IsWiki : true ,
538
+ IsWiki : isWiki ,
553
539
}, input )
554
540
assert .NoError (t , err )
555
- assert . Equal ( t , strings .TrimSpace (expectedWiki ), strings . TrimSpace ( string (buffer ) ))
541
+ return strings .TrimSpace (string (buffer ))
556
542
}
557
543
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 )
560
546
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 )
565
549
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 )
570
558
}
571
559
572
560
func Test_ParseClusterFuzz (t * testing.T ) {
@@ -719,5 +707,6 @@ func TestIssue18471(t *testing.T) {
719
707
func TestIsFullURL (t * testing.T ) {
720
708
assert .True (t , markup .IsFullURLString ("https://example.com" ))
721
709
assert .True (t , markup .IsFullURLString ("mailto:test@example.com" ))
710
+ assert .True (t , markup .IsFullURLString ("data:image/11111" ))
722
711
assert .False (t , markup .IsFullURLString ("/foo:bar" ))
723
712
}
0 commit comments