Allow to save empty comment (#30706)

Fix #29986
This commit is contained in:
wxiaoguang 2024-04-26 09:17:43 +08:00 committed by GitHub
parent 935330b1b9
commit 6a0750177f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3149,13 +3149,10 @@ func UpdateCommentContent(ctx *context.Context) {
}
oldContent := comment.Content
comment.Content = ctx.FormString("content")
if len(comment.Content) == 0 {
ctx.JSON(http.StatusOK, map[string]any{
"content": "",
})
return
}
newContent := ctx.FormString("content")
// allow to save empty content
comment.Content = newContent
if err = issue_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil {
if errors.Is(err, user_model.ErrBlockedUser) {
ctx.JSONError(ctx.Tr("repo.issues.comment.blocked_user"))
@ -3178,7 +3175,9 @@ func UpdateCommentContent(ctx *context.Context) {
}
}
content, err := markdown.RenderString(&markup.RenderContext{
var renderedContent template.HTML
if comment.Content != "" {
renderedContent, err = markdown.RenderString(&markup.RenderContext{
Links: markup.Links{
Base: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
},
@ -3190,9 +3189,13 @@ func UpdateCommentContent(ctx *context.Context) {
ctx.ServerError("RenderString", err)
return
}
} else {
contentEmpty := fmt.Sprintf(`<span class="no-content">%s</span>`, ctx.Tr("repo.issues.no_content"))
renderedContent = template.HTML(contentEmpty)
}
ctx.JSON(http.StatusOK, map[string]any{
"content": content,
"content": renderedContent,
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
})
}