diff --git a/main.go b/main.go index 990bd2f..2ff76cc 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "fmt" "io" "io/fs" + "net" "net/http" "net/url" "os" @@ -464,11 +465,16 @@ func main() { } if *serverFlag != "" { - var idnaProfile = idna.New(idna.MapForLookup(), idna.BidiRule()) - // See an explanation in git-pages auth.go for why this replacement is done. - if _, err := idnaProfile.ToASCII(strings.ReplaceAll(*serverFlag, "_", "a")); err != nil { - fmt.Fprintf(os.Stderr, "error: --server must be used with a domain name: %q\n", *serverFlag) + if serverHost, _, err := net.SplitHostPort(*serverFlag); err != nil { + fmt.Fprintf(os.Stderr, "error: invalid --server value %q\n", *serverFlag) os.Exit(usageExitCode) + } else { + var idnaProfile = idna.New(idna.MapForLookup(), idna.BidiRule()) + // See an explanation in git-pages auth.go for why this replacement is done. + if _, err := idnaProfile.ToASCII(strings.ReplaceAll(serverHost, "_", "a")); err != nil { + fmt.Fprintf(os.Stderr, "error: --server must be used with a domain name: %q\n", serverHost) + os.Exit(usageExitCode) + } } }