web: reject any whitespace-only input

This commit is contained in:
Alexey Yerin 2021-05-11 11:32:38 +03:00
parent e1c610caf9
commit c792f7f570
1 changed files with 2 additions and 1 deletions

3
web.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"html/template" "html/template"
"net/http" "net/http"
"strings"
) )
func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func(w http.ResponseWriter, req *http.Request) { func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func(w http.ResponseWriter, req *http.Request) {
@ -24,7 +25,7 @@ func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func
to := req.FormValue("to") to := req.FormValue("to")
text := req.FormValue("text") text := req.FormValue("text")
if text == "" { if strings.TrimSpace(text) == "" {
tmpl.ExecuteTemplate(w, "index", indexPageData{Languages, from, to, text, ""}) tmpl.ExecuteTemplate(w, "index", indexPageData{Languages, from, to, text, ""})
return return
} }