mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1219 from unihorn/148
flags/urls: reject url without port
This commit is contained in:
commit
b3c7711da8
@ -3,6 +3,7 @@ package flags
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
@ -28,6 +29,9 @@ func (us *URLs) Set(s string) error {
|
||||
if u.Scheme != "http" && u.Scheme != "https" {
|
||||
return fmt.Errorf("URL scheme must be http or https: %s", s)
|
||||
}
|
||||
if _, _, err := net.SplitHostPort(u.Host); err != nil {
|
||||
return fmt.Errorf(`URL address does not have the form "host:port": %s`, s)
|
||||
}
|
||||
if u.Path != "" {
|
||||
return fmt.Errorf("URL must not contain a path: %s", s)
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ func TestValidateURLsBad(t *testing.T) {
|
||||
"234#$",
|
||||
"file://foo/bar",
|
||||
"http://hello/asdf",
|
||||
"http://10.1.1.1",
|
||||
}
|
||||
for i, in := range tests {
|
||||
u := URLs{}
|
||||
@ -34,7 +35,8 @@ func TestValidateURLsGood(t *testing.T) {
|
||||
tests := []string{
|
||||
"https://1.2.3.4:8080",
|
||||
"http://10.1.1.1:80",
|
||||
"http://10.1.1.1",
|
||||
"http://localhost:80",
|
||||
"http://:80",
|
||||
}
|
||||
for i, in := range tests {
|
||||
u := URLs{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user