From 3bdb380a1a32ac254a4c4aeb9fa7688c1d540578 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Mon, 29 Apr 2024 13:31:49 -0700 Subject: [PATCH] don't change public signature of endpointaddr.Parse() --- internal/endpointaddr/endpointaddr.go | 8 ++------ internal/endpointaddr/endpointaddr_test.go | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/internal/endpointaddr/endpointaddr.go b/internal/endpointaddr/endpointaddr.go index ebf1db88a..dd475e7fc 100644 --- a/internal/endpointaddr/endpointaddr.go +++ b/internal/endpointaddr/endpointaddr.go @@ -42,7 +42,7 @@ func (h *HostPort) Endpoint() string { // - "[]:" (IPv6 address with port, brackets are required) // // If the input does not specify a port number, then defaultPort will be used. -func Parse(endpoint string, defaultPort uint16, paths ...string) (HostPort, error) { +func Parse(endpoint string, defaultPort uint16) (HostPort, error) { // Try parsing it both with and without an implicit port 443 at the end. host, port, err := net.SplitHostPort(endpoint) @@ -62,13 +62,9 @@ func Parse(endpoint string, defaultPort uint16, paths ...string) (HostPort, erro return HostPort{}, fmt.Errorf("invalid port %q", port) } - if len(paths) < 1 { - paths = []string{"UNKNOWN_PATH"} - } - // Check if the host part is a IPv4 or IPv6 address or a valid hostname according to RFC 1123. switch { - case len(validation.IsValidIP(field.NewPath(paths[0], paths[1:]...), host)) == 0: + case len(validation.IsValidIP(field.NewPath("UNKNOWN_PATH"), host)) == 0: case len(validation.IsDNS1123Subdomain(host)) == 0: default: return HostPort{}, fmt.Errorf("host %q is not a valid hostname or IP address", host) diff --git a/internal/endpointaddr/endpointaddr_test.go b/internal/endpointaddr/endpointaddr_test.go index 15972c907..91c68b0d6 100644 --- a/internal/endpointaddr/endpointaddr_test.go +++ b/internal/endpointaddr/endpointaddr_test.go @@ -17,7 +17,6 @@ func TestParse(t *testing.T) { name string input string defaultPort uint16 - paths []string expectErr string expect HostPort expectEndpoint string @@ -47,7 +46,6 @@ func TestParse(t *testing.T) { name: "invalid IPv4", input: "1.1.1.", defaultPort: 443, - paths: []string{"does", "not", "matter", "because", "this", "error", "is", "ignored"}, expectErr: `host "1.1.1." is not a valid hostname or IP address`, }, { @@ -178,7 +176,7 @@ func TestParse(t *testing.T) { } { tt := tt t.Run(tt.name, func(t *testing.T) { - got, err := Parse(tt.input, tt.defaultPort, tt.paths...) + got, err := Parse(tt.input, tt.defaultPort) if tt.expectErr == "" { assert.NoError(t, err) assert.Equal(t, tt.expect, got)