Skip to content

Commit

Permalink
allow for blank ip addresses (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
duhruh authored Jun 4, 2021
1 parent 85dd5c8 commit d5e0c06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func newIPValue(val net.IP, p *net.IP) *ipValue {

func (i *ipValue) String() string { return net.IP(*i).String() }
func (i *ipValue) Set(s string) error {
if s == "" {
return nil
}
ip := net.ParseIP(strings.TrimSpace(s))
if ip == nil {
return fmt.Errorf("failed to parse IP: %q", s)
Expand Down
2 changes: 1 addition & 1 deletion ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestIP(t *testing.T) {
{"1.2.3.4", true, "1.2.3.4"},
{"127.0.0.1", true, "127.0.0.1"},
{"255.255.255.255", true, "255.255.255.255"},
{"", false, ""},
{"", true, "0.0.0.0"},
{"0", false, ""},
{"localhost", false, ""},
{"0.0.0", false, ""},
Expand Down

0 comments on commit d5e0c06

Please sign in to comment.