aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-04-26 09:17:43 +0800
committerGitHub <noreply@github.com>2024-04-26 01:17:43 +0000
commit6a0750177fe4c494f828463bc146ea11df08a422 (patch)
treec8cf02ae885a8772d0b3dc4770532c987c58d5a2 /routers
parent935330b1b98a232f2928d55e96dc425e09bda593 (diff)
downloadgitea-6a0750177fe4c494f828463bc146ea11df08a422.tar.gz
gitea-6a0750177fe4c494f828463bc146ea11df08a422.zip
Allow to save empty comment (#30706)
Fix #29986
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/issue.go41
1 files changed, 22 insertions, 19 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index 95f0cf3d71..1bc5f343e7 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -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,21 +3175,27 @@ func UpdateCommentContent(ctx *context.Context) {
}
}
- content, err := markdown.RenderString(&markup.RenderContext{
- Links: markup.Links{
- Base: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
- },
- Metas: ctx.Repo.Repository.ComposeMetas(ctx),
- GitRepo: ctx.Repo.GitRepo,
- Ctx: ctx,
- }, comment.Content)
- if err != nil {
- ctx.ServerError("RenderString", err)
- return
+ var renderedContent template.HTML
+ if comment.Content != "" {
+ renderedContent, err = markdown.RenderString(&markup.RenderContext{
+ Links: markup.Links{
+ Base: ctx.FormString("context"), // FIXME: <- IS THIS SAFE ?
+ },
+ Metas: ctx.Repo.Repository.ComposeMetas(ctx),
+ GitRepo: ctx.Repo.GitRepo,
+ Ctx: ctx,
+ }, comment.Content)
+ if err != nil {
+ 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),
})
}