Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ func parseHost(host []byte) ([]byte, error) {
return append(host1, append(host2, host3...)...), nil
}
} else if i := bytes.LastIndexByte(host, ':'); i != -1 {
if bytes.IndexByte(host[:i], ':') != -1 {
return nil, fmt.Errorf("invalid host %q with multiple port delimiters", host)
}
colonPort := host[i:]
if !validOptionalPort(colonPort) {
return nil, fmt.Errorf("invalid port %q after host", colonPort)
Expand Down
21 changes: 21 additions & 0 deletions uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ func TestURIRejectInvalidScheme(t *testing.T) {
}
}

func TestURIRejectMultiplePorts(t *testing.T) {
t.Parallel()

testcases := []string{
"http://192.168.1.1:1111:2222/",
"http://example.com:80:8080/",
}

for _, raw := range testcases {
var u URI
if err := u.Parse(nil, []byte(raw)); err == nil {
t.Fatalf("expected Parse to fail for %q", raw)
}
}

var valid URI
if err := valid.Parse(nil, []byte("http://192.168.1.1:1111/")); err != nil {
t.Fatalf("unexpected error for valid uri: %v", err)
}
}

func TestURIUpdate(t *testing.T) {
t.Parallel()

Expand Down