lib/netutil/netutil: fix strings index check

### Describe Your Changes

Properly check precense of `/`, previously it was 
ignoring a case where "/" would be at the beginning of the string.

This is a follow-up for 00712b18

---------

Signed-off-by: Zakhar Bessarab <z.bessarab@victoriametrics.com>
This commit is contained in:
Zakhar Bessarab
2025-06-06 09:01:50 +04:00
committed by GitHub
parent f68f5b3113
commit 107b6517b7
2 changed files with 2 additions and 1 deletions

View File

@@ -80,7 +80,7 @@ func IsErrMissingPort(err error) bool {
// It returns the normalized address in the form "host:port".
// It is expected that addr is in the form "host" or "host:port".
func NormalizeAddr(addr string, defaultPort int) (string, error) {
if strings.Index(addr, "/") > 0 {
if strings.Contains(addr, "/") {
return "", fmt.Errorf("invalid address %q; expected format: host:port", addr)
}

View File

@@ -65,4 +65,5 @@ func TestNormalizeAddrError(t *testing.T) {
f("http://127.0.0.1:80")
f("http://vmstorage-0.svc.cluster.local.")
f("http://vmstorage-0.svc.cluster.local.:80")
f("/vmstorage-0.svc.cluster.local.:80")
}