From b482e20e2c9ec447f0e9dfd4a1c2cebb22c76694 Mon Sep 17 00:00:00 2001 From: Robin Lai Date: Thu, 23 Jan 2020 14:09:04 -0800 Subject: [PATCH] remove hostname validation --- utils/grpc/client.go | 23 ----------------------- utils/grpc/client_test.go | 15 +-------------- 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/utils/grpc/client.go b/utils/grpc/client.go index 22bf106..b35a3ee 100644 --- a/utils/grpc/client.go +++ b/utils/grpc/client.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "net/url" - "regexp" "strconv" "strings" "time" @@ -29,11 +28,6 @@ const ( defaultTimeout = 30 * time.Second ) -var ( - domainRegexp = regexp.MustCompile(`^(localhost)|([a-zA-Z0-9-]{1,63}\.)+([a-zA-Z]{1,63})$`) - ipv4Regexp = regexp.MustCompile(`^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$`) -) - func (g *ClientBuilder) doWithContext(ctx context.Context, f interface{}) error { newCtx, cancel := context.WithTimeout(ctx, g.timeout) if cancel != nil { @@ -114,9 +108,6 @@ func parse(rawU string) (*parsedURL, error) { return nil, err } h := u.Hostname() - if err := checkHost(h); err != nil { - return nil, err - } result := new(parsedURL) result.schema = u.Scheme result.host = h @@ -142,20 +133,6 @@ func getPort(u *url.URL) (int, error) { return strconv.Atoi(p) } -func checkHost(host string) error { - if host == "" { - return errors.New("empty host") - } - host = strings.ToLower(host) - if domainRegexp.MatchString(host) { - return nil - } - if ipv4Regexp.MatchString(host) { - return nil - } - return fmt.Errorf("invalid host: %v", host) -} - type parsedURL struct { schema string host string diff --git a/utils/grpc/client_test.go b/utils/grpc/client_test.go index 85f6211..4506742 100644 --- a/utils/grpc/client_test.go +++ b/utils/grpc/client_test.go @@ -48,22 +48,8 @@ func TestParse(t *testing.T) { out *parsedURL err bool }{ - {in: "", err: true}, - {in: "/", err: true}, - {in: "//", err: true}, - {in: "http:/www.google.com", err: true}, - {in: "http:///www.google.com", err: true}, - {in: "javascript:void(0)", err: true}, - {in: "