@@ -10,26 +10,21 @@ import (
1010 "code.gitea.io/gitea/modules/git"
1111 "code.gitea.io/gitea/modules/markup"
1212 "code.gitea.io/gitea/modules/setting"
13- "code.gitea.io/gitea/modules/util"
1413
1514 "github.com/stretchr/testify/assert"
1615)
1716
18- const (
19- AppURL = "http://localhost:3000/"
20- Repo = "gogits/gogs"
21- AppSubURL = AppURL + Repo + "/"
22- )
17+ const AppURL = "http://localhost:3000/"
2318
2419func TestRender_StandardLinks (t * testing.T ) {
2520 setting .AppURL = AppURL
26- setting .AppSubURL = AppSubURL
2721
2822 test := func (input , expected string ) {
2923 buffer , err := RenderString (& markup.RenderContext {
3024 Ctx : git .DefaultContext ,
3125 Links : markup.Links {
32- Base : setting .AppSubURL ,
26+ Base : "/relative-path" ,
27+ BranchPath : "branch/main" ,
3328 },
3429 }, input )
3530 assert .NoError (t , err )
@@ -38,32 +33,30 @@ func TestRender_StandardLinks(t *testing.T) {
3833
3934 test ("[[https://google.com/]]" ,
4035 `<p><a href="https://google.com/">https://google.com/</a></p>` )
41-
42- lnk := util . URLJoin ( AppSubURL , " WikiPage" )
43- test ("[[WikiPage][WikiPage ]]" ,
44- `<p><a href="` + lnk + `">WikiPage </a></p>` )
36+ test ( "[[WikiPage][The WikiPage Desc]]" ,
37+ `<p><a href="/relative-path/ WikiPage">The WikiPage Desc</a></p>` )
38+ test ("[[ImageLink.svg][The Image Desc ]]" ,
39+ `<p><a href="/relative-path/media/branch/main/ImageLink.svg">The Image Desc </a></p>` )
4540}
4641
4742func TestRender_Media (t * testing.T ) {
4843 setting .AppURL = AppURL
49- setting .AppSubURL = AppSubURL
5044
5145 test := func (input , expected string ) {
5246 buffer , err := RenderString (& markup.RenderContext {
5347 Ctx : git .DefaultContext ,
5448 Links : markup.Links {
55- Base : setting . AppSubURL ,
49+ Base : "./relative-path" ,
5650 },
5751 }, input )
5852 assert .NoError (t , err )
5953 assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (buffer ))
6054 }
6155
62- url := "../../.images/src/02/train.jpg"
63- result := util .URLJoin (AppSubURL , url )
64-
65- test ("[[file:" + url + "]]" ,
66- `<p><img src="` + result + `" alt="` + result + `" /></p>` )
56+ test ("[[file:../../.images/src/02/train.jpg]]" ,
57+ `<p><img src=".images/src/02/train.jpg" alt=".images/src/02/train.jpg" /></p>` )
58+ test ("[[file:train.jpg]]" ,
59+ `<p><img src="relative-path/train.jpg" alt="relative-path/train.jpg" /></p>` )
6760
6861 // With description.
6962 test ("[[https://example.com][https://example.com/example.svg]]" ,
@@ -80,11 +73,20 @@ func TestRender_Media(t *testing.T) {
8073 `<p><img src="https://example.com/example.svg" alt="https://example.com/example.svg" /></p>` )
8174 test ("[[https://example.com/example.mp4]]" ,
8275 `<p><video src="https://example.com/example.mp4">https://example.com/example.mp4</video></p>` )
76+
77+ // test [[LINK][DESCRIPTION]] syntax with "file:" prefix
78+ test (`[[https://example.com/][file:https://example.com/foo%20bar.svg]]` ,
79+ `<p><a href="https://example.com/"><img src="https://example.com/foo%20bar.svg" alt="https://example.com/foo%20bar.svg" /></a></p>` )
80+ test (`[[file:https://example.com/foo%20bar.svg][Goto Image]]` ,
81+ `<p><a href="https://example.com/foo%20bar.svg">Goto Image</a></p>` )
82+ test (`[[file:https://example.com/link][https://example.com/image.jpg]]` ,
83+ `<p><a href="https://example.com/link"><img src="https://example.com/image.jpg" alt="https://example.com/image.jpg" /></a></p>` )
84+ test (`[[file:https://example.com/link][file:https://example.com/image.jpg]]` ,
85+ `<p><a href="https://example.com/link"><img src="https://example.com/image.jpg" alt="https://example.com/image.jpg" /></a></p>` )
8386}
8487
8588func TestRender_Source (t * testing.T ) {
8689 setting .AppURL = AppURL
87- setting .AppSubURL = AppSubURL
8890
8991 test := func (input , expected string ) {
9092 buffer , err := RenderString (& markup.RenderContext {
0 commit comments