@@ -53,7 +53,7 @@ func TestRender_Commits(t *testing.T) {
53
53
}
54
54
55
55
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
56
- repo := markup . TestRepoURL
56
+ repo := "http://localhost:3000/gogits/gogs"
57
57
commit := util .URLJoin (repo , "commit" , sha )
58
58
tree := util .URLJoin (repo , "tree" , sha , "src" )
59
59
@@ -107,8 +107,8 @@ func TestRender_CrossReferences(t *testing.T) {
107
107
}
108
108
109
109
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>` )
112
112
test (
113
113
"go-gitea/gitea#12345" ,
114
114
`<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) {
517
517
}
518
518
519
519
func 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 {
523
521
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 ,
538
524
Metas : localMetas ,
539
- IsWiki : true ,
525
+ IsWiki : isWiki ,
540
526
}, input )
541
527
assert .NoError (t , err )
542
- assert . Equal ( t , strings .TrimSpace (expectedWiki ), strings . TrimSpace ( string (buffer ) ))
528
+ return strings .TrimSpace (string (buffer ))
543
529
}
544
530
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 )
547
533
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 )
552
536
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 )
557
545
}
558
546
559
547
func Test_ParseClusterFuzz (t * testing.T ) {
@@ -706,5 +694,6 @@ func TestIssue18471(t *testing.T) {
706
694
func TestIsFullURL (t * testing.T ) {
707
695
assert .True (t , markup .IsFullURLString ("https://example.com" ))
708
696
assert .True (t , markup .IsFullURLString ("mailto:test@example.com" ))
697
+ assert .True (t , markup .IsFullURLString ("data:image/11111" ))
709
698
assert .False (t , markup .IsFullURLString ("/foo:bar" ))
710
699
}
0 commit comments