1
0

Filter new lines.

This commit is contained in:
Alexander Andreev 2023-03-11 23:34:08 +04:00
parent b90d238e71
commit 5d0d4e4034
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -118,6 +118,10 @@ func (h *Handlers) Guestbook(w http.ResponseWriter, r *http.Request) {
return return
} }
for _, entry := range entries {
entry.Message = strings.ReplaceAll(entry.Message, "\\n", "\n")
}
entriesCount, _ := h.guestbookDB.Count() entriesCount, _ := h.guestbookDB.Count()
pageCount := int64(math.Ceil(float64(entriesCount) / float64(h.guestbookPageSize))) pageCount := int64(math.Ceil(float64(entriesCount) / float64(h.guestbookPageSize)))
@ -143,7 +147,11 @@ func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
r.Form.Set("name", "Anonymous") r.Form.Set("name", "Anonymous")
} }
entry, err = guestbook.NewEntry(r.FormValue("name"), 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")
entry, err = guestbook.NewEntry(r.FormValue("name"), message,
r.FormValue("website"), r.FormValue("hide_website") != "") r.FormValue("website"), r.FormValue("hide_website") != "")
if err != nil { if err != nil {
h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w) h.InternalError(err.Error(), "Here's your message:"+r.FormValue("message"), w)
@ -163,6 +171,9 @@ func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
func (h *Handlers) GuestbookAdmin(w http.ResponseWriter, r *http.Request) { func (h *Handlers) GuestbookAdmin(w http.ResponseWriter, r *http.Request) {
entriesCount, _ := h.guestbookDB.Count() entriesCount, _ := h.guestbookDB.Count()
entries, err := h.guestbookDB.Entries(1, entriesCount) entries, err := h.guestbookDB.Entries(1, entriesCount)
for _, entry := range entries {
entry.Message = strings.ReplaceAll(entry.Message, "\\n", "\n")
}
if err != nil { if err != nil {
return return
} }