From fefd6dbdce418054f43a8f91cdae5213edeaad21 Mon Sep 17 00:00:00 2001 From: cdramey Date: Sat, 17 Nov 2018 17:17:22 +0000 Subject: [PATCH] Improved URL validation --- qurl/qurl.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qurl/qurl.go b/qurl/qurl.go index fd1812d..fa4e3b7 100644 --- a/qurl/qurl.go +++ b/qurl/qurl.go @@ -29,6 +29,14 @@ func (q *QURL) CheckValid() error { return err } + if u.Scheme == "" { + return fmt.Errorf("URLs must begin with a scheme (e.g. https:)") + } + + if u.Host == "" && u.RawQuery == "" && u.RawPath == "" && u.Fragment == "" { + return fmt.Errorf("URLs must contain a path, host, query or fragment element") + } + if !u.IsAbs() { return fmt.Errorf("Relative URLs are not allowed") }