comment methods ro private
This commit is contained in:
+1
-1
@@ -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 {
|
||||
|
||||
+12
-12
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user