fix validateAddressFormat

This commit is contained in:
eyedeekay
2025-05-26 22:28:54 -04:00
parent d844519847
commit faf6b8e93e

View File

@ -3,6 +3,7 @@ package i2pkeys
import ( import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"net"
"strings" "strings"
) )
@ -61,6 +62,10 @@ func sanitizeAddress(addr string) string {
func validateAddressFormat(addr string) error { func validateAddressFormat(addr string) error {
host, _, err := net.SplitHostPort(addr) host, _, err := net.SplitHostPort(addr)
if err != nil {
// If SplitHostPort fails, it means addr is not in host:port format
host = addr
}
if host != "" { if host != "" {
addr = host addr = host
} }
@ -68,11 +73,9 @@ func validateAddressFormat(addr string) error {
return fmt.Errorf("invalid address length: got %d, want between %d and %d", return fmt.Errorf("invalid address length: got %d, want between %d and %d",
len(addr), MinAddressLength, MaxAddressLength) len(addr), MinAddressLength, MaxAddressLength)
} }
if strings.HasSuffix(addr, B32Suffix) { if strings.HasSuffix(addr, B32Suffix) {
return fmt.Errorf("cannot convert %s to full destination", B32Suffix) return fmt.Errorf("cannot convert %s to full destination", B32Suffix)
} }
return nil return nil
} }