diff --git a/modules/markup/html.go b/modules/markup/html.go index 930c6b3a3..adc2bef53 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -625,6 +625,9 @@ func crossReferenceIssueIndexPatternProcessor(ctx *postProcessCtx, node *html.No // fullSha1PatternProcessor renders SHA containing URLs func fullSha1PatternProcessor(ctx *postProcessCtx, node *html.Node) { + if ctx.metas == nil { + return + } m := anySHA1Pattern.FindStringSubmatchIndex(node.Data) if m == nil { return @@ -686,7 +689,7 @@ func sha1CurrentPatternProcessor(ctx *postProcessCtx, node *html.Node) { // Although unlikely, deadbeef and 1234567 are valid short forms of SHA1 hash // as used by git and github for linking and thus we have to do similar. replaceContent(node, m[2], m[3], - createCodeLink(util.URLJoin(ctx.urlPrefix, "commit", hash), base.ShortSha(hash))) + createCodeLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], "commit", hash), base.ShortSha(hash))) } // emailAddressProcessor replaces raw email addresses with a mailto: link. diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index 6d3da3193..543db1d46 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -16,12 +16,17 @@ import ( "github.com/stretchr/testify/assert" ) +var localMetas = map[string]string{ + "user": "gogits", + "repo": "gogs", +} + func TestRender_Commits(t *testing.T) { setting.AppURL = AppURL setting.AppSubURL = AppSubURL test := func(input, expected string) { - buffer := RenderString(".md", input, setting.AppSubURL, nil) + buffer := RenderString(".md", input, setting.AppSubURL, localMetas) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) } @@ -45,7 +50,7 @@ func TestRender_CrossReferences(t *testing.T) { setting.AppSubURL = AppSubURL test := func(input, expected string) { - buffer := RenderString("a.md", input, setting.AppSubURL, nil) + buffer := RenderString("a.md", input, setting.AppSubURL, localMetas) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) } @@ -195,7 +200,7 @@ func TestRender_ShortLinks(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer := markdown.RenderString(input, tree, nil) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer))) - buffer = markdown.RenderWiki([]byte(input), setting.AppSubURL, nil) + buffer = markdown.RenderWiki([]byte(input), setting.AppSubURL, localMetas) assert.Equal(t, strings.TrimSpace(expectedWiki), strings.TrimSpace(string(buffer))) } diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index 8ba51e6a1..2128639b9 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -103,6 +103,8 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
See commit fc7f44dadf
Ideas and codes