Skip to content

Commit

Permalink
allow for blank ip addresses (spf13#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
duhruh authored and djdv committed Jul 5, 2022
1 parent 91c4515 commit 880355b
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 @@ -19,6 +19,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 @@ -27,7 +27,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 880355b

Please sign in to comment.