validate TLD
This commit is contained in:
parent
95bb6041a3
commit
fd01dbc34e
19
main.go
19
main.go
@ -107,13 +107,22 @@ 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
|
||||
}
|
||||
ret, err := url.ParseRequestURI(uri)
|
||||
return ret, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
splits := strings.Split(ret.Hostname(), ".")
|
||||
if len(splits) <= 1 {
|
||||
return nil, errors.New("hostname doesn't have a TLD")
|
||||
}
|
||||
|
||||
if _, ok := TLDs[splits[len(splits)-1]]; !ok {
|
||||
return nil, errors.New("invalid top level domain")
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
1098
top_level_domains.go
Normal file
1098
top_level_domains.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user