Made a func cleanupNewlines() to replace repeats across handlers.
This commit is contained in:
parent
5b62a77fb8
commit
99f76234a0
@ -37,9 +37,7 @@ func (h *GuestbookApiHandlers) New(w http.ResponseWriter, r *http.Request) {
|
||||
r.Form.Set("name", "Anonymous")
|
||||
}
|
||||
|
||||
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
|
||||
message = strings.ReplaceAll(message, "\n\r", "\n")
|
||||
message = strings.ReplaceAll(message, "\r", "\n")
|
||||
message := cleanupNewlines(r.FormValue("message"))
|
||||
|
||||
entry, err = justguestbook.NewEntry(r.FormValue("name"), message,
|
||||
r.FormValue("website"), r.FormValue("hide_website") != "")
|
||||
@ -68,9 +66,7 @@ func (h *GuestbookApiHandlers) Edit(w http.ResponseWriter, r *http.Request) {
|
||||
r.Form.Set("name", "Anonymous")
|
||||
}
|
||||
|
||||
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
|
||||
message = strings.ReplaceAll(message, "\n\r", "\n")
|
||||
message = strings.ReplaceAll(message, "\r", "\n")
|
||||
message := cleanupNewlines(r.FormValue("message"))
|
||||
|
||||
entry, err = justguestbook.NewEntry(r.FormValue("name"), message,
|
||||
r.FormValue("website"), r.FormValue("hide_website") != "")
|
||||
@ -106,9 +102,7 @@ func (h *GuestbookApiHandlers) Reply(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
|
||||
|
||||
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
|
||||
message = strings.ReplaceAll(message, "\n\r", "\n")
|
||||
message = strings.ReplaceAll(message, "\r", "\n")
|
||||
message := cleanupNewlines(r.FormValue("message"))
|
||||
|
||||
reply, err = justguestbook.NewReply(id, message)
|
||||
if err != nil {
|
||||
@ -132,9 +126,7 @@ func (h *GuestbookApiHandlers) EditReply(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
id, _ := strconv.ParseInt(httpr.Param(r, "id"), 10, 64)
|
||||
|
||||
message := strings.ReplaceAll(r.FormValue("message"), "\r\n", "\n")
|
||||
message = strings.ReplaceAll(message, "\n\r", "\n")
|
||||
message = strings.ReplaceAll(message, "\r", "\n")
|
||||
message := cleanupNewlines(r.FormValue("message"))
|
||||
|
||||
reply, err = justguestbook.NewReply(id, message)
|
||||
if err != nil {
|
||||
|
@ -66,9 +66,7 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||
r.ParseForm()
|
||||
|
||||
body := strings.ReplaceAll(r.FormValue("body"), "\r\n", "\n")
|
||||
body = strings.ReplaceAll(body, "\n\r", "\n")
|
||||
body = strings.ReplaceAll(body, "\r", "\n")
|
||||
body := cleanupNewlines(r.FormValue("body"))
|
||||
|
||||
if r.FormValue("category") != "" {
|
||||
category, err = mindflow.NewCategory(r.FormValue("new-category"))
|
||||
|
@ -175,3 +175,9 @@ func SitemapXml(w http.ResponseWriter, r *http.Request) {
|
||||
func Error(w http.ResponseWriter, code int, reason, message string) {
|
||||
web.ErrorXXX("/"+http.StatusText(code), reason, message, code, w)
|
||||
}
|
||||
|
||||
func cleanupNewlines(text string) (out string) {
|
||||
out = strings.ReplaceAll(text, "\r\n", "\n")
|
||||
out = strings.ReplaceAll(out, "\n\r", "\n")
|
||||
return strings.ReplaceAll(out, "\r", "\n")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user