Skip to content

Commit 6a07501

Browse files
authored
Allow to save empty comment (#30706)
Fix #29986
1 parent 935330b commit 6a07501

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

routers/web/repo/issue.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,13 +3149,10 @@ func UpdateCommentContent(ctx *context.Context) {
31493149
}
31503150

31513151
oldContent := comment.Content
3152-
comment.Content = ctx.FormString("content")
3153-
if len(comment.Content) == 0 {
3154-
ctx.JSON(http.StatusOK, map[string]any{
3155-
"content": "",
3156-
})
3157-
return
3158-
}
3152+
newContent := ctx.FormString("content")
3153+
3154+
// allow to save empty content
3155+
comment.Content = newContent
31593156
if err = issue_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {
31603157
if errors.Is(err, user_model.ErrBlockedUser) {
31613158
ctx.JSONError(ctx.Tr("repo.issues.comment.blocked_user"))
@@ -3178,21 +3175,27 @@ func UpdateCommentContent(ctx *context.Context) {
31783175
}
31793176
}
31803177

3181-
content, err := markdown.RenderString(&markup.RenderContext{
3182-
Links: markup.Links{
3183-
Base: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
3184-
},
3185-
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
3186-
GitRepo: ctx.Repo.GitRepo,
3187-
Ctx: ctx,
3188-
}, comment.Content)
3189-
if err != nil {
3190-
ctx.ServerError("RenderString", err)
3191-
return
3178+
var renderedContent template.HTML
3179+
if comment.Content != "" {
3180+
renderedContent, err = markdown.RenderString(&markup.RenderContext{
3181+
Links: markup.Links{
3182+
Base: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
3183+
},
3184+
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
3185+
GitRepo: ctx.Repo.GitRepo,
3186+
Ctx: ctx,
3187+
}, comment.Content)
3188+
if err != nil {
3189+
ctx.ServerError("RenderString", err)
3190+
return
3191+
}
3192+
} else {
3193+
contentEmpty := fmt.Sprintf(`<span class="no-content">%s</span>`, ctx.Tr("repo.issues.no_content"))
3194+
renderedContent = template.HTML(contentEmpty)
31923195
}
31933196

31943197
ctx.JSON(http.StatusOK, map[string]any{
3195-
"content": content,
3198+
"content": renderedContent,
31963199
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
31973200
})
31983201
}

0 commit comments

Comments
 (0)