From 0d37f3a79bd1aa0bea391a4ca978c722666698d3 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Thu, 25 Apr 2024 11:20:04 +0200 Subject: [PATCH 1/2] test: empty existing comment --- tests/integration/issue_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 84487a847a..49d1cbb016 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -307,6 +307,16 @@ func TestIssueCommentUpdate(t *testing.T) { comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: commentID}) assert.Equal(t, modifiedContent, comment.Content) + + // make the comment empty + req = NewRequestWithValues(t, "POST", fmt.Sprintf("/%s/%s/comments/%d", "user2", "repo1", commentID), map[string]string{ + "_csrf": GetCSRF(t, session, issueURL), + "content": "", + }) + session.MakeRequest(t, req, http.StatusOK) + + comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: commentID}) + assert.Equal(t, "", comment.Content) } func TestIssueReaction(t *testing.T) { From ea9051624d174808b6f3a656f050240c1e0347f4 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Thu, 25 Apr 2024 11:21:39 +0200 Subject: [PATCH 2/2] comment: save empty comments --- routers/web/repo/issue.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 520737809b..b0b4b65331 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -3160,12 +3160,6 @@ 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 - } if err = issue_service.UpdateComment(ctx, comment, ctx.Doer, oldContent); err != nil { ctx.ServerError("UpdateComment", err) return