From b505b3b81c70feabbdd66299bf36461fa136e7da Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Wed, 8 Feb 2017 10:50:17 -0800 Subject: [PATCH] Correct port parsing. (#2354) * Correct port parsing. Fixes #2351 * use strings.Contains instead of strings.HasSuffix * Make the error message point to the wrong input --- command/server.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/command/server.go b/command/server.go index f2cd7413e3..cf8a442d49 100644 --- a/command/server.go +++ b/command/server.go @@ -312,15 +312,19 @@ func (c *ServerCommand) Run(args []string) int { return 1 } host, port, err := net.SplitHostPort(u.Host) - nPort, nPortErr := strconv.Atoi(port) if err != nil { - // assume it's due to there not being a port specified, in which case - // use 443 - host = u.Host - nPort = 443 + // This sucks, as it's a const in the function but not exported in the package + if strings.Contains(err.Error(), "missing port in address") { + host = u.Host + port = "443" + } else { + c.Ui.Output(fmt.Sprintf("Error parsing redirect address: %v", err)) + return 1 + } } - if nPortErr != nil { - c.Ui.Output(fmt.Sprintf("Cannot parse %s as a numeric port: %v", port, nPortErr)) + nPort, err := strconv.Atoi(port) + if err != nil { + c.Ui.Output(fmt.Sprintf("Error parsing redirect address; failed to convert %q to a numeric: %v", port, err)) return 1 } u.Host = net.JoinHostPort(host, strconv.Itoa(nPort+1))