Support IPv6 server addresses without ports

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-09 23:55:51 -04:00
committed by Brandon McGinty
parent 770635955a
commit d7dcaa8b21
2 changed files with 24 additions and 3 deletions
+14
View File
@@ -69,6 +69,20 @@ func TestNotificationExpansionIsSinglePassAndNotifyDoesNotBlock(t *testing.T) {
}
}
func TestServerAddressDefaultsPortWithoutBreakingIPv6(t *testing.T) {
for input, want := range map[string]string{
"server": "server:64738",
"server:64739": "server:64739",
"::1": "[::1]:64738",
"[2001:db8::1]": "[2001:db8::1]:64738",
"[2001:db8::1]:9": "[2001:db8::1]:9",
} {
if got := serverAddress(input); got != want {
t.Errorf("serverAddress(%q) = %q, want %q", input, got, want)
}
}
}
func TestPublicServerMessageDoesNotPanic(t *testing.T) {
channel := &gumble.Channel{ID: 1, Name: "Current"}
b := &Barnard{
+10 -3
View File
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"os/exec"
@@ -226,9 +227,7 @@ func main() {
os.Exit(0)
}
if !strings.Contains(*server, ":") {
*server = (*server + ":64738")
}
*server = serverAddress(*server)
// Initialize
b := Barnard{
@@ -282,6 +281,14 @@ func main() {
handle_error(&b)
}
// serverAddress adds Mumble's default port without corrupting an IPv6 literal.
func serverAddress(address string) string {
if _, port, err := net.SplitHostPort(address); err == nil && port != "" {
return address
}
return net.JoinHostPort(strings.Trim(address, "[]"), "64738")
}
func handle_raw_error(e error) {
fmt.Fprintf(os.Stderr, "%s\n", e.Error())
os.Exit(1)