dont parse strings without tld as uri

This commit is contained in:
Timon Ringwald 2022-05-08 18:19:41 +02:00
parent e9e6f9b2a8
commit 35867a5a63

View File

@ -2,6 +2,7 @@ package main
import ( import (
"embed" "embed"
"errors"
"flag" "flag"
"fmt" "fmt"
"html/template" "html/template"
@ -106,6 +107,10 @@ func search(w http.ResponseWriter, r *http.Request) {
} }
func ParseURI(uri string) (*url.URL, error) { func ParseURI(uri string) (*url.URL, error) {
if !strings.ContainsRune(uri, '.') {
return nil, errors.New("no top level domain")
}
if !strings.HasPrefix(uri, "http://") && !strings.HasPrefix(uri, "https://") { if !strings.HasPrefix(uri, "http://") && !strings.HasPrefix(uri, "https://") {
uri = "https://" + uri uri = "https://" + uri
} }