Skip to content

unsafe-formatted-url-host-port

Default severity: warning

Formatting a URL authority or an address passed directly to a standard-library network listener as host:port does not add the brackets required around IPv6 literals. net.JoinHostPort correctly handles hostnames, IPv4, and IPv6.

url := fmt.Sprintf("http://%s:%d/path", host, port)
address := net.JoinHostPort(host, strconv.Itoa(port)); url := "http://" + address