From 35867a5a6359d9c0c79a8e32bbd637a27aecfd3a Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Sun, 8 May 2022 18:19:41 +0200 Subject: [PATCH] dont parse strings without tld as uri --- main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.go b/main.go index 2aa5804..a313b22 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "embed" + "errors" "flag" "fmt" "html/template" @@ -106,6 +107,10 @@ func search(w http.ResponseWriter, r *http.Request) { } 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://") { uri = "https://" + uri }