move comment size validation to raw comment #3
This commit is contained in:
@@ -137,9 +137,14 @@ func (s *Rest) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
comment.PrepareUntrusted() // clean all fields user not suppoed to set
|
||||
comment.PrepareUntrusted() // clean all fields user not supposed to set
|
||||
comment.User = user
|
||||
comment.User.IP = strings.Split(r.RemoteAddr, ":")[0]
|
||||
if err = s.DataService.ValidateComment(&comment); err != nil {
|
||||
rest.SendErrorJSON(w, r, http.StatusBadRequest, err, "invalid comment")
|
||||
return
|
||||
}
|
||||
|
||||
comment.Text = string(blackfriday.Run([]byte(comment.Text), blackfriday.WithExtensions(mdExt)))
|
||||
log.Printf("[DEBUG] create comment %+v", comment)
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ func (s *Service) Create(comment Comment) (commentID string, err error) {
|
||||
comment.Votes = make(map[string]bool)
|
||||
}
|
||||
|
||||
if err = s.ValidateComment(&comment); err != nil {
|
||||
return "", err
|
||||
}
|
||||
comment.Sanitize() // clear potentially dangerous js from all parts of comment
|
||||
comment.User.hashIP(s.Secret) // replace ip by hash
|
||||
|
||||
@@ -111,10 +108,6 @@ func (s *Service) EditComment(locator Locator, commentID string, text string, ed
|
||||
comment.Edit = &edit
|
||||
comment.Edit.Timestamp = time.Now()
|
||||
|
||||
if err = s.ValidateComment(&comment); err != nil {
|
||||
return comment, err
|
||||
}
|
||||
|
||||
comment.Sanitize()
|
||||
err = s.Put(locator, comment)
|
||||
return comment, err
|
||||
|
||||
@@ -85,7 +85,7 @@ func TestService_Vote(t *testing.T) {
|
||||
assert.Equal(t, map[string]bool{"user1": true}, c.Votes, "user voted +")
|
||||
|
||||
c, err = b.Vote(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, res[0].ID, "user", true)
|
||||
assert.NotNil(t, "self-voting not allowed")
|
||||
assert.NotNil(t, err, "self-voting not allowed")
|
||||
|
||||
_, err = b.Vote(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, res[0].ID, "user1", true)
|
||||
assert.NotNil(t, err, "double-voting rejected")
|
||||
@@ -178,7 +178,7 @@ func TestService_EditCommentDurationFailed(t *testing.T) {
|
||||
|
||||
time.Sleep(time.Second)
|
||||
|
||||
comment, err = b.EditComment(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, res[0].ID, "xxx",
|
||||
_, err = b.EditComment(Locator{URL: "https://radio-t.com", SiteID: "radio-t"}, res[0].ID, "xxx",
|
||||
Edit{Summary: "my edit"})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user