From 0495499b4f0f82eae5599b4c44e06dcb9030771e Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 21 Jan 2019 09:13:55 +0100 Subject: [PATCH] fix ip address parsing of loopback address --- pkg/util/ip_address.go | 6 ++++-- pkg/util/ip_address_test.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/util/ip_address.go b/pkg/util/ip_address.go index 4e9a9378c6b..d8d95ef3acd 100644 --- a/pkg/util/ip_address.go +++ b/pkg/util/ip_address.go @@ -7,11 +7,13 @@ import ( // ParseIPAddress parses an IP address and removes port and/or IPV6 format func ParseIPAddress(input string) string { - var s string + s := input lastIndex := strings.LastIndex(input, ":") if lastIndex != -1 { - s = input[:lastIndex] + if lastIndex > 0 && input[lastIndex-1:lastIndex] != ":" { + s = input[:lastIndex] + } } s = strings.Replace(s, "[", "", -1) diff --git a/pkg/util/ip_address_test.go b/pkg/util/ip_address_test.go index 644340a5e82..fd3e3ea8587 100644 --- a/pkg/util/ip_address_test.go +++ b/pkg/util/ip_address_test.go @@ -10,5 +10,7 @@ func TestParseIPAddress(t *testing.T) { Convey("Test parse ip address", t, func() { So(ParseIPAddress("192.168.0.140:456"), ShouldEqual, "192.168.0.140") So(ParseIPAddress("[::1:456]"), ShouldEqual, "127.0.0.1") + So(ParseIPAddress("[::1]"), ShouldEqual, "127.0.0.1") + So(ParseIPAddress("192.168.0.140"), ShouldEqual, "192.168.0.140") }) }