diff --git a/modules/csv/csv_test.go b/modules/csv/csv_test.go index c627597fa..6b91a81fc 100644 --- a/modules/csv/csv_test.go +++ b/modules/csv/csv_test.go @@ -11,6 +11,7 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/markup" "github.com/stretchr/testify/assert" @@ -229,7 +230,10 @@ John Doe john@doe.com This,note,had,a,lot,of,commas,to,test,delimiters`, } for n, c := range cases { - delimiter := determineDelimiter(&markup.RenderContext{RelativePath: c.filename}, []byte(decodeSlashes(t, c.csv))) + delimiter := determineDelimiter(&markup.RenderContext{ + Ctx: git.DefaultContext, + RelativePath: c.filename, + }, []byte(decodeSlashes(t, c.csv))) assert.EqualValues(t, c.expectedDelimiter, delimiter, "case %d: delimiter should be equal, expected '%c' got '%c'", n, c.expectedDelimiter, delimiter) } } diff --git a/modules/markup/console/console_test.go b/modules/markup/console/console_test.go index 506f86194..2337d91ac 100644 --- a/modules/markup/console/console_test.go +++ b/modules/markup/console/console_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/markup" "github.com/stretchr/testify/assert" @@ -23,7 +24,8 @@ func TestRenderConsole(t *testing.T) { canRender := render.CanRender("test", strings.NewReader(k)) assert.True(t, canRender) - err := render.Render(&markup.RenderContext{}, strings.NewReader(k), &buf) + err := render.Render(&markup.RenderContext{Ctx: git.DefaultContext}, + strings.NewReader(k), &buf) assert.NoError(t, err) assert.EqualValues(t, v, buf.String()) } diff --git a/modules/markup/csv/csv_test.go b/modules/markup/csv/csv_test.go index b9f5769be..8c07184b2 100644 --- a/modules/markup/csv/csv_test.go +++ b/modules/markup/csv/csv_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/markup" "github.com/stretchr/testify/assert" @@ -23,7 +24,8 @@ func TestRenderCSV(t *testing.T) { for k, v := range kases { var buf strings.Builder - err := render.Render(&markup.RenderContext{}, strings.NewReader(k), &buf) + err := render.Render(&markup.RenderContext{Ctx: git.DefaultContext}, + strings.NewReader(k), &buf) assert.NoError(t, err) assert.EqualValues(t, v, buf.String()) } diff --git a/modules/markup/html.go b/modules/markup/html.go index bcb38f99e..76fc54cf4 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -291,9 +291,10 @@ func RenderDescriptionHTML( // RenderEmoji for when we want to just process emoji and shortcodes // in various places it isn't already run through the normal markdown processor func RenderEmoji( + ctx *RenderContext, content string, ) (string, error) { - return renderProcessString(&RenderContext{}, emojiProcessors, content) + return renderProcessString(ctx, emojiProcessors, content) } var ( diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 6746c40d1..a048f1f52 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" @@ -70,8 +71,13 @@ var localMetas = map[string]string{ func TestRender_IssueIndexPattern(t *testing.T) { // numeric: render inputs without valid mentions test := func(s string) { - testRenderIssueIndexPattern(t, s, s, &RenderContext{}) - testRenderIssueIndexPattern(t, s, s, &RenderContext{Metas: numericMetas}) + testRenderIssueIndexPattern(t, s, s, &RenderContext{ + Ctx: git.DefaultContext, + }) + testRenderIssueIndexPattern(t, s, s, &RenderContext{ + Ctx: git.DefaultContext, + Metas: numericMetas, + }) } // should not render anything when there are no mentions @@ -119,7 +125,10 @@ func TestRender_IssueIndexPattern2(t *testing.T) { links[i] = numericIssueLink(util.URLJoin(TestRepoURL, path), "ref-issue", index, marker) } expectedNil := fmt.Sprintf(expectedFmt, links...) - testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{Metas: localMetas}) + testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{ + Ctx: git.DefaultContext, + Metas: localMetas, + }) class := "ref-issue" if isExternal { @@ -130,7 +139,10 @@ func TestRender_IssueIndexPattern2(t *testing.T) { links[i] = numericIssueLink(prefix, class, index, marker) } expectedNum := fmt.Sprintf(expectedFmt, links...) - testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{Metas: numericMetas}) + testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{ + Ctx: git.DefaultContext, + Metas: numericMetas, + }) } // should render freestanding mentions @@ -164,7 +176,10 @@ func TestRender_IssueIndexPattern3(t *testing.T) { // alphanumeric: render inputs without valid mentions test := func(s string) { - testRenderIssueIndexPattern(t, s, s, &RenderContext{Metas: alphanumericMetas}) + testRenderIssueIndexPattern(t, s, s, &RenderContext{ + Ctx: git.DefaultContext, + Metas: alphanumericMetas, + }) } test("") test("this is a test") @@ -194,7 +209,10 @@ func TestRender_IssueIndexPattern4(t *testing.T) { links[i] = externalIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue ref-external-issue", name) } expected := fmt.Sprintf(expectedFmt, links...) - testRenderIssueIndexPattern(t, s, expected, &RenderContext{Metas: alphanumericMetas}) + testRenderIssueIndexPattern(t, s, expected, &RenderContext{ + Ctx: git.DefaultContext, + Metas: alphanumericMetas, + }) } test("OTT-1234 test", "%s test", "OTT-1234") test("test T-12 issue", "test %s issue", "T-12") @@ -214,7 +232,10 @@ func TestRender_IssueIndexPattern5(t *testing.T) { } expected := fmt.Sprintf(expectedFmt, links...) - testRenderIssueIndexPattern(t, s, expected, &RenderContext{Metas: metas}) + testRenderIssueIndexPattern(t, s, expected, &RenderContext{ + Ctx: git.DefaultContext, + Metas: metas, + }) } test("abc ISSUE-123 def", "abc %s def", @@ -235,7 +256,10 @@ func TestRender_IssueIndexPattern5(t *testing.T) { []string{"ISSUE-123"}, ) - testRenderIssueIndexPattern(t, "will not match", "will not match", &RenderContext{Metas: regexpMetas}) + testRenderIssueIndexPattern(t, "will not match", "will not match", &RenderContext{ + Ctx: git.DefaultContext, + Metas: regexpMetas, + }) } func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *RenderContext) { @@ -255,6 +279,7 @@ func TestRender_AutoLink(t *testing.T) { test := func(input, expected string) { var buffer strings.Builder err := PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: TestRepoURL, Metas: localMetas, }, strings.NewReader(input), &buffer) @@ -263,6 +288,7 @@ func TestRender_AutoLink(t *testing.T) { buffer.Reset() err = PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: TestRepoURL, Metas: localMetas, IsWiki: true, @@ -292,6 +318,7 @@ func TestRender_FullIssueURLs(t *testing.T) { test := func(input, expected string) { var result strings.Builder err := postProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: TestRepoURL, Metas: localMetas, }, []processor{fullIssuePatternProcessor}, strings.NewReader(input), &result) diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index aea1d9267..f8b84485c 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -91,6 +91,7 @@ func TestRender_CrossReferences(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(&RenderContext{ + Ctx: git.DefaultContext, RelativePath: "a.md", URLPrefix: setting.AppSubURL, Metas: localMetas, @@ -135,6 +136,7 @@ func TestRender_links(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(&RenderContext{ + Ctx: git.DefaultContext, RelativePath: "a.md", URLPrefix: TestRepoURL, }, input) @@ -234,6 +236,7 @@ func TestRender_email(t *testing.T) { test := func(input, expected string) { res, err := RenderString(&RenderContext{ + Ctx: git.DefaultContext, RelativePath: "a.md", URLPrefix: TestRepoURL, }, input) @@ -292,6 +295,7 @@ func TestRender_emoji(t *testing.T) { test := func(input, expected string) { expected = strings.ReplaceAll(expected, "&", "&") buffer, err := RenderString(&RenderContext{ + Ctx: git.DefaultContext, RelativePath: "a.md", URLPrefix: TestRepoURL, }, input) @@ -355,11 +359,13 @@ func TestRender_ShortLinks(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer, err := markdown.RenderString(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: tree, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) buffer, err = markdown.RenderString(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: TestRepoURL, Metas: localMetas, IsWiki: true, @@ -461,12 +467,14 @@ func TestRender_RelativeImages(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer, err := markdown.RenderString(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: tree, Metas: localMetas, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) buffer, err = markdown.RenderString(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: TestRepoURL, Metas: localMetas, IsWiki: true, @@ -501,6 +509,7 @@ func Test_ParseClusterFuzz(t *testing.T) { var res strings.Builder err := PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, }, strings.NewReader(data), &res) @@ -511,6 +520,7 @@ func Test_ParseClusterFuzz(t *testing.T) { res.Reset() err = PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, }, strings.NewReader(data), &res) @@ -531,6 +541,7 @@ func TestIssue16020(t *testing.T) { var res strings.Builder err := PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, }, strings.NewReader(data), &res) @@ -547,6 +558,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { for i := 0; i < b.N; i++ { var res strings.Builder err := PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, }, strings.NewReader(data), &res) @@ -557,6 +569,7 @@ func BenchmarkEmojiPostprocess(b *testing.B) { func TestFuzz(t *testing.T) { s := "t/l/issues/8#/../../a" renderContext := RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com/go-gitea/gitea", Metas: map[string]string{ "user": "go-gitea", @@ -574,6 +587,7 @@ func TestIssue18471(t *testing.T) { var res strings.Builder err := PostProcess(&RenderContext{ + Ctx: git.DefaultContext, URLPrefix: "https://example.com", Metas: localMetas, }, strings.NewReader(data), &res) diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index bb458a65c..0c7650a5f 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -52,12 +52,14 @@ func TestRender_StandardLinks(t *testing.T) { test := func(input, expected, expectedWiki string) { buffer, err := RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, }, input) assert.NoError(t, err) assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) buffer, err = RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, IsWiki: true, }, input) @@ -81,6 +83,7 @@ func TestRender_Images(t *testing.T) { test := func(input, expected string) { buffer, err := RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, URLPrefix: setting.AppSubURL, }, input) assert.NoError(t, err) @@ -311,6 +314,7 @@ func TestTotal_RenderWiki(t *testing.T) { for i := 0; i < len(testCases); i += 2 { line, err := RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, URLPrefix: AppSubURL, IsWiki: true, }, testCases[i]) @@ -339,6 +343,7 @@ func TestTotal_RenderString(t *testing.T) { for i := 0; i < len(testCases); i += 2 { line, err := RenderString(&markup.RenderContext{ + Ctx: git.DefaultContext, URLPrefix: AppSubURL, }, testCases[i]) assert.NoError(t, err) @@ -348,17 +353,17 @@ func TestTotal_RenderString(t *testing.T) { func TestRender_RenderParagraphs(t *testing.T) { test := func(t *testing.T, str string, cnt int) { - res, err := RenderRawString(&markup.RenderContext{}, str) + res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, str) assert.NoError(t, err) assert.Equal(t, cnt, strings.Count(res, "
` - res, err := RenderRawString(&markup.RenderContext{}, testcase) + res, err := RenderRawString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) assert.Equal(t, expected, res) } @@ -407,7 +412,7 @@ func TestRenderEmojiInLinks_Issue12331(t *testing.T) { testcase := `[Link with emoji :moon: in text](https://gitea.io)` expected := ` ` - res, err := RenderString(&markup.RenderContext{}, testcase) + res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, testcase) assert.NoError(t, err) assert.Equal(t, expected, res) } @@ -441,7 +446,7 @@ func TestColorPreview(t *testing.T) { } for _, test := range positiveTests { - res, err := RenderString(&markup.RenderContext{}, test.testcase) + res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test.testcase) assert.NoError(t, err, "Unexpected error in testcase: %q", test.testcase) assert.Equal(t, test.expected, res, "Unexpected result in testcase %q", test.testcase) @@ -461,7 +466,7 @@ func TestColorPreview(t *testing.T) { } for _, test := range negativeTests { - res, err := RenderString(&markup.RenderContext{}, test) + res, err := RenderString(&markup.RenderContext{Ctx: git.DefaultContext}, test) assert.NoError(t, err, "Unexpected error in testcase: %q", test) assert.NotContains(t, res, `` for _, label := range labels { // Protect against nil value in labels - shouldn't happen but would cause a panic if so @@ -396,7 +396,7 @@ func NewFuncMap() []template.FuncMap { continue } htmlCode += fmt.Sprintf("%s ", - repoLink, label.ID, RenderLabel(label)) + repoLink, label.ID, RenderLabel(ctx, label)) } htmlCode += "" return template.HTML(htmlCode) @@ -808,7 +808,7 @@ func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[str } // RenderLabel renders a label -func RenderLabel(label *issues_model.Label) string { +func RenderLabel(ctx context.Context, label *issues_model.Label) string { labelScope := label.ExclusiveScope() textColor := "#111" @@ -821,12 +821,12 @@ func RenderLabel(label *issues_model.Label) string { if labelScope == "" { // Regular label return fmt.Sprintf("{{$.locale.Tr "repo.activity.merged_prs_label"}} - #{{.Index}} {{.Issue.Title | RenderEmoji}} + #{{.Index}} {{.Issue.Title | RenderEmoji $.Context}} {{TimeSinceUnix .MergedUnix $.locale}}
{{end}} @@ -168,7 +168,7 @@ {{range .Activity.OpenedPRs}}{{$.locale.Tr "repo.activity.opened_prs_label"}} - #{{.Index}} {{.Issue.Title | RenderEmoji}} + #{{.Index}} {{.Issue.Title | RenderEmoji $.Context}} {{TimeSinceUnix .Issue.CreatedUnix $.locale}}
{{end}} @@ -187,7 +187,7 @@ {{range .Activity.ClosedIssues}}{{$.locale.Tr "repo.activity.closed_issue_label"}} - #{{.Index}} {{.Title | RenderEmoji}} + #{{.Index}} {{.Title | RenderEmoji $.Context}} {{TimeSinceUnix .ClosedUnix $.locale}}
{{end}} @@ -206,7 +206,7 @@ {{range .Activity.OpenedIssues}}{{$.locale.Tr "repo.activity.new_issue_label"}} - #{{.Index}} {{.Title | RenderEmoji}} + #{{.Index}} {{.Title | RenderEmoji $.Context}} {{TimeSinceUnix .CreatedUnix $.locale}}
{{end}} @@ -227,9 +227,9 @@ {{$.locale.Tr "repo.activity.unresolved_conv_label"}} #{{.Index}} {{if .IsPull}} - {{.Title | RenderEmoji}} + {{.Title | RenderEmoji $.Context}} {{else}} - {{.Title | RenderEmoji}} + {{.Title | RenderEmoji $.Context}} {{end}} {{TimeSinceUnix .UpdatedUnix $.locale}} diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index eaf86ab4e..36333c554 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -61,7 +61,7 @@