Updated url regex to allow for any scheme

This commit is contained in:
sloumdrone 2019-09-26 18:30:44 -07:00
parent 5e68d81a63
commit 7896858fac
1 changed files with 2 additions and 1 deletions

3
url.go
View File

@ -37,7 +37,7 @@ type Url struct {
// an error (or nil).
func MakeUrl(u string) (Url, error) {
var out Url
re := regexp.MustCompile(`^((?P<scheme>gopher|telnet|http|https|gemini):\/\/)?(?P<host>[\w\-\.\d]+)(?::(?P<port>\d+)?)?(?:/(?P<type>[01345679gIhisp])?)?(?P<resource>.*)?$`)
re := regexp.MustCompile(`^((?P<scheme>[a-zA-Z]+):\/\/)?(?P<host>[\w\-\.\d]+)(?::(?P<port>\d+)?)?(?:/(?P<type>[01345679gIhisp])?)?(?P<resource>.*)?$`)
match := re.FindStringSubmatch(u)
if valid := re.MatchString(u); !valid {
@ -58,6 +58,7 @@ func MakeUrl(u string) (Url, error) {
out.Resource = match[i]
}
}
out.Scheme = strings.ToLower(out.Scheme)
if out.Scheme == "" {
out.Scheme = "gopher"