diff --git a/listener/listener.go b/listener/listener.go index b3ecda6..7da9dd6 100644 --- a/listener/listener.go +++ b/listener/listener.go @@ -83,7 +83,7 @@ func (l UnixListener) Listen() (net.Listener, error) { } // Being lazy here... -var reLooksLikeHostPort = regexp.MustCompile(`^(\d+):(\d+)$`) +var reLooksLikeHostPort = regexp.MustCompile(`^(.+?):(\d+)$`) var reLooksLikePort = regexp.MustCompile(`^\d+$`) func parseListenTargets(str string) ([]Listener, error) { @@ -103,14 +103,14 @@ func parseListenTargets(str string) ([]Listener, error) { return nil, fmt.Errorf("failed to parse '%s' as listen target: %s", pairString, err) } - if matches := reLooksLikeHostPort.FindAllString(hostPort, -1); matches != nil { - port, err := strconv.ParseInt(matches[1], 10, 0) + if matches := reLooksLikeHostPort.FindStringSubmatch(hostPort); matches != nil { + port, err := strconv.ParseInt(matches[2], 10, 0) if err != nil { return nil, err } ret[i] = TCPListener{ - Addr: matches[0], + Addr: matches[1], Port: int(port), fd: uintptr(fd), } diff --git a/listener/listener_test.go b/listener/listener_test.go index 3232a4e..f3ee8a3 100644 --- a/listener/listener_test.go +++ b/listener/listener_test.go @@ -22,6 +22,11 @@ func TestPort(t *testing.T) { if port.Fd() != expect[i].Fd() { t.Errorf("parsed fd is not what we expected (expected %d, got %d)", expect[i].Fd(), port.Fd()) } + _, gotTcp := port.(TCPListener) + _, expectTcp := expect[i].(TCPListener) + if gotTcp != expectTcp { + t.Errorf("parsed listener is the wrong type") + } } }