escape html in text and name

This commit is contained in:
Eugene
2017-12-20 18:23:38 -06:00
parent 1fe92d2d70
commit 4a99c704a4
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# remark
# remark [![Build Status](http://drone.umputun.com:9080/api/badges/umputun/remark/status.svg)](http://drone.umputun.com:9080/umputun/remark)
description
+6 -2
View File
@@ -1,6 +1,7 @@
package rest
import (
"html/template"
"log"
"net/http"
"strconv"
@@ -29,7 +30,7 @@ func (s *Server) Run() {
router.Post("/comment", s.createCommentCtrl)
router.Delete("/comment/{id}", s.deleteCommentCtrl)
router.Get("/find", s.getUrlComments)
router.Get("/find", s.getURLComments)
router.Get("/last/{max}", s.getLastComments)
router.Get("/id/{id}", s.getByID)
log.Fatal(http.ListenAndServe(":8080", router))
@@ -44,7 +45,10 @@ func (s *Server) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
httpError(w, r, http.StatusBadRequest, err, "can't bind comment")
return
}
comment.User.IP = strings.Split(r.RemoteAddr, ":")[0]
comment.User.Name = template.HTMLEscapeString(comment.User.Name)
comment.Text = template.HTMLEscapeString(comment.Text)
log.Printf("[INFO] create comment %+v", comment)
@@ -83,7 +87,7 @@ func (s *Server) deleteCommentCtrl(w http.ResponseWriter, r *http.Request) {
}
// GET /find?url=post-url
func (s *Server) getUrlComments(w http.ResponseWriter, r *http.Request) {
func (s *Server) getURLComments(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
log.Printf("[INFO] get comments for %s", url)