Correct validation for TCPAddrResolvable

pull/234/head
joeybloggs 9 years ago
parent 7b758151c6
commit faf40fd62f
  1. 12
      baked_in.go
  2. 2
      validator_test.go

@ -87,13 +87,13 @@ var bakedInValidators = map[string]Func{
"tcp4_addr": IsTCP4AddrResolvable,
"tcp6_addr": IsTCP6AddrResolvable,
"tcp_addr": IsTCPAddrResolvable,
"udp4_addr": IsUDP4AddrResolvable,
"udp6_addr": IsUDP6AddrResolvable,
"udp_addr": IsUDPAddrResolvable,
"udp4_addr": IsUDP4AddrResolvable, // need to do
"udp6_addr": IsUDP6AddrResolvable, // need to do
"udp_addr": IsUDPAddrResolvable, // need to do
"ip4_addr": IsIP4AddrResolvable,
"ip6_addr": IsIP6AddrResolvable,
"ip_addr": IsIPAddrResolvable,
"unix_addr": IsUnixAddrResolvable,
"unix_addr": IsUnixAddrResolvable, // need to do
"mac": IsMAC,
}
@ -1290,6 +1290,10 @@ func IsTCP6AddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrF
func IsTCPAddrResolvable(v *Validate, topStruct reflect.Value, currentStructOrField reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool {
// if string before the post is blank then invalid
if !IsTCP4AddrResolvable(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) &&
!IsTCP6AddrResolvable(v, topStruct, currentStructOrField, field, fieldType, fieldKind, param) {
return false
}
_, err := net.ResolveTCPAddr("tcp", field.String())
return err == nil

@ -1993,7 +1993,7 @@ func TestTCPAddrValidation(t *testing.T) {
param string
expected bool
}{
{":80", true},
{":80", false},
{"127.0.0.1:80", true},
{"[::1]:80", true},
{"256.0.0.0:1", false},

Loading…
Cancel
Save