]> source.dussan.org Git - gitea.git/commitdiff
Allow to save empty comment (#30706)
authorwxiaoguang <wxiaoguang@gmail.com>
Fri, 26 Apr 2024 01:17:43 +0000 (09:17 +0800)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 01:17:43 +0000 (01:17 +0000)
Fix #29986

routers/web/repo/issue.go

index 95f0cf3d71cff5752080ab337104eb29b12f24ac..1bc5f343e7d9e5a2d034229f14026ac3f6a56aeb 100644 (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,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),
        })
 }