support raw urls

This commit is contained in:
2023-09-12 22:37:04 -07:00
parent 7285264fed
commit 552e1e3ac1
7 changed files with 37 additions and 63 deletions

View File

@@ -10,7 +10,7 @@ import (
"net/http"
"strings"
"git.sr.ht/~kisom/goutils/config"
"git.wntrmute.dev/kyle/goutils/config"
"git.wntrmute.dev/kyle/kls/links"
"github.com/jackc/pgx/v4/pgxpool"
)
@@ -46,13 +46,15 @@ func (srv *server) postURL(w http.ResponseWriter, r *http.Request) {
return
}
isRawURL := boolean(r.FormValue("rawp"))
url := r.FormValue("value")
if len(url) == 0 {
http.Error(w, "invalid URL", http.StatusBadRequest)
return
}
url, err = links.CleanString(url)
url, err = links.CleanString(url, isRawURL)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@@ -122,3 +124,12 @@ func (srv *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
srv.servePage(w, page{}, "index.tpl")
}
func boolean(s string) bool {
switch s {
case "on", "true", "True", "yes", "Yes":
return true
default:
return false
}
}