Merge pull request #5363 from akerouanton/fix-ps-pbs

cli/formatter: bracket IPv6 addrs prepended to ports
This commit is contained in:
Sebastiaan van Stijn 2024-08-20 17:51:14 +02:00 committed by GitHub
commit d47c36debb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -5,6 +5,7 @@ package formatter
import ( import (
"fmt" "fmt"
"net"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -331,7 +332,8 @@ func DisplayablePorts(ports []container.Port) string {
portKey := port.Type portKey := port.Type
if port.IP != "" { if port.IP != "" {
if port.PublicPort != current { if port.PublicPort != current {
hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type)) hAddrPort := net.JoinHostPort(port.IP, strconv.Itoa(int(port.PublicPort)))
hostMappings = append(hostMappings, fmt.Sprintf("%s->%d/%s", hAddrPort, port.PrivatePort, port.Type))
continue continue
} }
portKey = port.IP + "/" + port.Type portKey = port.IP + "/" + port.Type

View File

@ -558,6 +558,16 @@ func TestDisplayablePorts(t *testing.T) {
}, },
expected: "0.0.0.0:0->9988/tcp", expected: "0.0.0.0:0->9988/tcp",
}, },
{
ports: []container.Port{
{
IP: "::",
PrivatePort: 9988,
Type: "tcp",
},
},
expected: "[::]:0->9988/tcp",
},
{ {
ports: []container.Port{ ports: []container.Port{
{ {