diff --git a/internal/http/api_handlers.go b/internal/http/api_handlers.go index ffba01b..aa4b216 100644 --- a/internal/http/api_handlers.go +++ b/internal/http/api_handlers.go @@ -108,8 +108,14 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) { if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { r.ParseForm() + id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64) - reply, err = guestbook.NewReply(id, r.FormValue("message")) + + message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n") + message = strings.ReplaceAll(message, "\n\r", "\n") + message = strings.ReplaceAll(message, "\r", "\n") + + reply, err = guestbook.NewReply(id, message) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -128,8 +134,14 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request) if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") { r.ParseForm() + id, _ := strconv.ParseInt(GetURLParam(r, "id"), 10, 64) - reply, err = guestbook.NewReply(id, r.FormValue("message")) + + message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n") + message = strings.ReplaceAll(message, "\n\r", "\n") + message = strings.ReplaceAll(message, "\r", "\n") + + reply, err = guestbook.NewReply(id, message) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return