Skip to content

Commit 312fc2b

Browse files
committed
add more some tests
1 parent ef1af4a commit 312fc2b

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

models/renderhelper/repo_file_test.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ func TestRepoFile(t *testing.T) {
3535
})
3636

3737
t.Run("AbsoluteAndRelative", func(t *testing.T) {
38-
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
39-
CurrentRefPath: "branch/main",
40-
}).WithMarkupType(markdown.MarkupName)
38+
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{CurrentRefPath: "branch/main"}).
39+
WithMarkupType(markdown.MarkupName)
4140
rendered, err := markup.RenderString(rctx, `
4241
[/test](/test)
4342
[./test](./test)
@@ -65,4 +64,20 @@ func TestRepoFile(t *testing.T) {
6564
<a href="/user2/repo1/media/commit/1234/image" target="_blank" rel="nofollow noopener"><img src="/user2/repo1/media/commit/1234/image" alt="/image"/></a></p>
6665
`, rendered)
6766
})
67+
68+
t.Run("WithCurrentRefPathByTag", func(t *testing.T) {
69+
rctx := NewRenderContextRepoFile(context.Background(), repo1, RepoFileOptions{
70+
CurrentRefPath: "/commit/1234",
71+
CurrentTreePath: "my-dir",
72+
}).
73+
WithMarkupType(markdown.MarkupName)
74+
rendered, err := markup.RenderString(rctx, `
75+
<img src="LINK">
76+
<video src="LINK">
77+
`)
78+
assert.NoError(t, err)
79+
assert.Equal(t, `<a href="/user2/repo1/media/commit/1234/my-dir/LINK" target="_blank" rel="nofollow noopener"><img src="/user2/repo1/media/commit/1234/my-dir/LINK"/></a>
80+
<video src="/user2/repo1/media/commit/1234/my-dir/LINK">
81+
</video>`, rendered)
82+
})
6883
}

modules/markup/html_node.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package markup
55

66
import (
7-
"code.gitea.io/gitea/modules/util"
8-
97
"golang.org/x/net/html"
108
)
119

@@ -17,7 +15,7 @@ func visitNodeImg(ctx *RenderContext, img *html.Node) (next *html.Node) {
1715
}
1816

1917
if IsNonEmptyRelativePath(attr.Val) {
20-
attr.Val = util.URLJoin(ctx.RenderHelper.ResolveLink(attr.Val, LinkTypeMedia))
18+
attr.Val = ctx.RenderHelper.ResolveLink(attr.Val, LinkTypeMedia)
2119

2220
// By default, the "<img>" tag should also be clickable,
2321
// because frontend use `<img>` to paste the re-scaled image into the markdown,
@@ -53,7 +51,7 @@ func visitNodeVideo(ctx *RenderContext, node *html.Node) (next *html.Node) {
5351
continue
5452
}
5553
if IsNonEmptyRelativePath(attr.Val) {
56-
attr.Val = util.URLJoin(ctx.RenderHelper.ResolveLink(attr.Val, LinkTypeMedia))
54+
attr.Val = ctx.RenderHelper.ResolveLink(attr.Val, LinkTypeMedia)
5755
}
5856
attr.Val = camoHandleLink(attr.Val)
5957
node.Attr[i] = attr

0 commit comments

Comments
 (0)