forked from tangled.org/core
this repo has no description
1package validator 2 3import ( 4 "fmt" 5 "strings" 6 7 "tangled.sh/tangled.sh/core/appview/db" 8 "tangled.sh/tangled.sh/core/appview/pages/markup" 9) 10 11func (v *Validator) ValidateIssueComment(comment *db.IssueComment) error { 12 // if comments have parents, only ingest ones that are 1 level deep 13 if comment.ReplyTo != nil { 14 parents, err := db.GetIssueComments(v.db, db.FilterEq("at_uri", *comment.ReplyTo)) 15 if err != nil { 16 return fmt.Errorf("failed to fetch parent comment: %w", err) 17 } 18 if len(parents) != 1 { 19 return fmt.Errorf("incorrect number of parent comments returned: %d", len(parents)) 20 } 21 22 // depth check 23 parent := parents[0] 24 if parent.ReplyTo != nil { 25 return fmt.Errorf("incorrect depth, this comment is replying at depth >1") 26 } 27 } 28 29 sanitizer := markup.NewSanitizer() 30 if sb := strings.TrimSpace(sanitizer.SanitizeDefault(comment.Body)); sb == "" { 31 return fmt.Errorf("body is empty after HTML sanitization") 32 } 33 34 return nil 35}