Skip to content

Commit c5193a8

Browse files
6543zeripath
andauthored
In Render tolerate not being passed a context (#16842) (#16858)
* In Render tolerate not being passed a context It is possible for RenderString to be passed to an external renderer if markdown is set to be rendered by an external renderer. No context is currently sent to these meaning that this will error out. Fix #16835 Signed-off-by: Andrew Thornton <[email protected]> * Add Context to Repo calls for RenderString All calls from routers can easily add the context - so add it. Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent 1790f01 commit c5193a8

File tree

7 files changed

+20
-1
lines changed

7 files changed

+20
-1
lines changed

modules/markup/external/external.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"strings"
1616

17+
"code.gitea.io/gitea/modules/graceful"
1718
"code.gitea.io/gitea/modules/log"
1819
"code.gitea.io/gitea/modules/markup"
1920
"code.gitea.io/gitea/modules/process"
@@ -99,7 +100,12 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
99100
}
100101

101102
if ctx == nil || ctx.Ctx == nil {
102-
return fmt.Errorf("RenderContext did not provide context")
103+
if ctx == nil {
104+
log.Warn("RenderContext not provided defaulting to empty ctx")
105+
ctx = &markup.RenderContext{}
106+
}
107+
log.Warn("RenderContext did not provide context, defaulting to Shutdown context")
108+
ctx.Ctx = graceful.GetManager().ShutdownContext()
103109
}
104110

105111
processCtx, cancel := context.WithCancel(ctx.Ctx)

routers/web/repo/issue.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ func ViewIssue(ctx *context.Context) {
11381138
URLPrefix: ctx.Repo.RepoLink,
11391139
Metas: ctx.Repo.Repository.ComposeMetas(),
11401140
GitRepo: ctx.Repo.GitRepo,
1141+
Ctx: ctx,
11411142
}, issue.Content)
11421143
if err != nil {
11431144
ctx.ServerError("RenderString", err)
@@ -1303,6 +1304,7 @@ func ViewIssue(ctx *context.Context) {
13031304
URLPrefix: ctx.Repo.RepoLink,
13041305
Metas: ctx.Repo.Repository.ComposeMetas(),
13051306
GitRepo: ctx.Repo.GitRepo,
1307+
Ctx: ctx,
13061308
}, comment.Content)
13071309
if err != nil {
13081310
ctx.ServerError("RenderString", err)
@@ -1379,6 +1381,7 @@ func ViewIssue(ctx *context.Context) {
13791381
URLPrefix: ctx.Repo.RepoLink,
13801382
Metas: ctx.Repo.Repository.ComposeMetas(),
13811383
GitRepo: ctx.Repo.GitRepo,
1384+
Ctx: ctx,
13821385
}, comment.Content)
13831386
if err != nil {
13841387
ctx.ServerError("RenderString", err)
@@ -1740,6 +1743,7 @@ func UpdateIssueContent(ctx *context.Context) {
17401743
URLPrefix: ctx.Query("context"),
17411744
Metas: ctx.Repo.Repository.ComposeMetas(),
17421745
GitRepo: ctx.Repo.GitRepo,
1746+
Ctx: ctx,
17431747
}, issue.Content)
17441748
if err != nil {
17451749
ctx.ServerError("RenderString", err)
@@ -2170,6 +2174,7 @@ func UpdateCommentContent(ctx *context.Context) {
21702174
URLPrefix: ctx.Query("context"),
21712175
Metas: ctx.Repo.Repository.ComposeMetas(),
21722176
GitRepo: ctx.Repo.GitRepo,
2177+
Ctx: ctx,
21732178
}, comment.Content)
21742179
if err != nil {
21752180
ctx.ServerError("RenderString", err)

routers/web/repo/milestone.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func Milestones(ctx *context.Context) {
8989
URLPrefix: ctx.Repo.RepoLink,
9090
Metas: ctx.Repo.Repository.ComposeMetas(),
9191
GitRepo: ctx.Repo.GitRepo,
92+
Ctx: ctx,
9293
}, m.Content)
9394
if err != nil {
9495
ctx.ServerError("RenderString", err)
@@ -282,6 +283,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) {
282283
URLPrefix: ctx.Repo.RepoLink,
283284
Metas: ctx.Repo.Repository.ComposeMetas(),
284285
GitRepo: ctx.Repo.GitRepo,
286+
Ctx: ctx,
285287
}, milestone.Content)
286288
if err != nil {
287289
ctx.ServerError("RenderString", err)

routers/web/repo/projects.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func Projects(ctx *context.Context) {
8282
URLPrefix: ctx.Repo.RepoLink,
8383
Metas: ctx.Repo.Repository.ComposeMetas(),
8484
GitRepo: ctx.Repo.GitRepo,
85+
Ctx: ctx,
8586
}, projects[i].Description)
8687
if err != nil {
8788
ctx.ServerError("RenderString", err)
@@ -324,6 +325,7 @@ func ViewProject(ctx *context.Context) {
324325
URLPrefix: ctx.Repo.RepoLink,
325326
Metas: ctx.Repo.Repository.ComposeMetas(),
326327
GitRepo: ctx.Repo.GitRepo,
328+
Ctx: ctx,
327329
}, project.Description)
328330
if err != nil {
329331
ctx.ServerError("RenderString", err)

routers/web/repo/release.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
146146
URLPrefix: ctx.Repo.RepoLink,
147147
Metas: ctx.Repo.Repository.ComposeMetas(),
148148
GitRepo: ctx.Repo.GitRepo,
149+
Ctx: ctx,
149150
}, r.Note)
150151
if err != nil {
151152
ctx.ServerError("RenderString", err)
@@ -215,6 +216,7 @@ func SingleRelease(ctx *context.Context) {
215216
URLPrefix: ctx.Repo.RepoLink,
216217
Metas: ctx.Repo.Repository.ComposeMetas(),
217218
GitRepo: ctx.Repo.GitRepo,
219+
Ctx: ctx,
218220
}, release.Note)
219221
if err != nil {
220222
ctx.ServerError("RenderString", err)

routers/web/user/home.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func Milestones(ctx *context.Context) {
272272
milestones[i].RenderedContent, err = markdown.RenderString(&markup.RenderContext{
273273
URLPrefix: milestones[i].Repo.Link(),
274274
Metas: milestones[i].Repo.ComposeMetas(),
275+
Ctx: ctx,
275276
}, milestones[i].Content)
276277
if err != nil {
277278
ctx.ServerError("RenderString", err)

routers/web/user/profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func Profile(ctx *context.Context) {
124124
URLPrefix: ctx.Repo.RepoLink,
125125
Metas: map[string]string{"mode": "document"},
126126
GitRepo: ctx.Repo.GitRepo,
127+
Ctx: ctx,
127128
}, ctxUser.Description)
128129
if err != nil {
129130
ctx.ServerError("RenderString", err)

0 commit comments

Comments
 (0)