From a9aeb7e4f09b2a32849befa3c9749f2f3e314244 Mon Sep 17 00:00:00 2001 From: Umputun Date: Thu, 22 Mar 2018 19:50:40 -0500 Subject: [PATCH] comment methods ro private --- app/store/bolt.go | 2 +- app/store/comment.go | 24 ++++++++++++------------ app/store/comment_test.go | 4 ++-- app/store/service.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/store/bolt.go b/app/store/bolt.go index 5d0f9c81..1feb1635 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -93,7 +93,7 @@ func (b *BoltDB) Create(comment Comment) (commentID string, err error) { comment.Votes = make(map[string]bool) } - comment.Sanitize() // clear potentially dangerous js from all parts of comment + comment.sanitize() // clear potentially dangerous js from all parts of comment bdb, err := b.db(comment.Locator.SiteID) if err != nil { diff --git a/app/store/comment.go b/app/store/comment.go index f4491a28..4c7fd250 100644 --- a/app/store/comment.go +++ b/app/store/comment.go @@ -75,8 +75,17 @@ func (c *Comment) PrepareUntrusted() { c.Deleted = false } -// Sanitize clean dangerous html/js from the comment -func (c *Comment) Sanitize() { +// SetDeleted clears comment info, reset to deleted state +func (c *Comment) SetDeleted() { + c.Text = "" + c.Score = 0 + c.Votes = map[string]bool{} + c.Edit = nil + c.Deleted = true +} + +// sanitize clean dangerous html/js from the comment +func (c *Comment) sanitize() { p := bluemonday.UGCPolicy() c.Text = p.Sanitize(c.Text) c.User.ID = template.HTMLEscapeString(c.User.ID) @@ -89,7 +98,7 @@ func (c *Comment) Sanitize() { } // HashUserFields replace sensitive fields with hashes -func (c *Comment) HashUserFields() { +func (c *Comment) hashUserFields() { hashVal := func(val string) string { if _, err := strconv.ParseUint(val, 16, 64); err == nil || val == "" { @@ -106,12 +115,3 @@ func (c *Comment) HashUserFields() { c.User.IP = hashVal(c.User.IP) c.User.ID = hashVal(c.User.ID) } - -// SetDeleted clears comment info, reset to deleted state -func (c *Comment) SetDeleted() { - c.Text = "" - c.Score = 0 - c.Votes = map[string]bool{} - c.Edit = nil - c.Deleted = true -} diff --git a/app/store/comment_test.go b/app/store/comment_test.go index dbfe61a9..39c1c1dc 100644 --- a/app/store/comment_test.go +++ b/app/store/comment_test.go @@ -27,7 +27,7 @@ func TestComment_Sanitize(t *testing.T) { } for n, tt := range tbl { - tt.inp.Sanitize() + tt.inp.sanitize() assert.Equal(t, tt.out, tt.inp, "check #%d", n) } } @@ -78,7 +78,7 @@ func TestComment_HashUserFields(t *testing.T) { } for n, tt := range tbl { - tt.inp.HashUserFields() + tt.inp.hashUserFields() assert.Equal(t, tt.out, tt.inp, "check #%d", n) } } diff --git a/app/store/service.go b/app/store/service.go index 1059214e..ca38d3ea 100644 --- a/app/store/service.go +++ b/app/store/service.go @@ -78,7 +78,7 @@ func (s *Service) EditComment(locator Locator, commentID string, text string, ed comment.Text = text comment.Edit = &edit comment.Edit.Timestamp = time.Now() - comment.Sanitize() + comment.sanitize() err = s.Put(locator, comment) return comment, err }