mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 21:22:44 +08:00
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.
This commit is contained in:

committed by
GitHub

parent
eadf324062
commit
886bad2fd5
@ -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
|
|||||||
|
|
||||||
// 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) {
|
|||||||
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")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user