Commit 886bad2f by Sofia Papagiannaki Committed by GitHub

Util: Modify SplitHostPortDefault not to return an error for empty input (#20351)

* Util: Optionally allow empty input in SplitHostPortDefault

Due to a recent change the SQL Server tests failed because passing an
empty datasource url in `util.SplitHostPortDefault` was no more allowed.
This fix contains the following modifications:
- Modifies the util.SplitHostPortDefault not to return an error for empty input.
- Modifies the util.SplitHostPort to return an error for empty input.
- Introduces an additional test for empty input.
parent eadf3240
...@@ -44,7 +44,7 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres ...@@ -44,7 +44,7 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres
Port: defaultPort, Port: defaultPort,
} }
if len(input) == 0 { if len(input) == 0 {
return addr, fmt.Errorf("Input is empty") return addr, nil
} }
start := 0 start := 0
...@@ -82,5 +82,8 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres ...@@ -82,5 +82,8 @@ func SplitHostPortDefault(input, defaultHost, defaultPort string) (NetworkAddres
// SplitHostPort splits ip address/hostname string by host and port // SplitHostPort splits ip address/hostname string by host and port
func SplitHostPort(input string) (NetworkAddress, error) { func SplitHostPort(input string) (NetworkAddress, error) {
if len(input) == 0 {
return NetworkAddress{}, fmt.Errorf("Input is empty")
}
return SplitHostPortDefault(input, "", "") return SplitHostPortDefault(input, "", "")
} }
...@@ -87,6 +87,11 @@ func TestSplitHostPortDefault(t *testing.T) { ...@@ -87,6 +87,11 @@ func TestSplitHostPortDefault(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(addr.Host, ShouldEqual, "xyz.rds.amazonaws.com") So(addr.Host, ShouldEqual, "xyz.rds.amazonaws.com")
So(addr.Port, ShouldEqual, "123") So(addr.Port, ShouldEqual, "123")
addr, err = SplitHostPortDefault("", "localhost", "1433")
So(err, ShouldBeNil)
So(addr.Host, ShouldEqual, "localhost")
So(addr.Port, ShouldEqual, "1433")
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment