Skip to content

Commit

Permalink
Merge pull request #5363 from akerouanton/fix-ps-pbs
Browse files Browse the repository at this point in the history
cli/formatter: bracket IPv6 addrs prepended to ports
  • Loading branch information
thaJeztah authored Aug 20, 2024
2 parents 986b077 + 964155c commit d47c36d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/command/formatter/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package formatter

import (
"fmt"
"net"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -331,7 +332,8 @@ func DisplayablePorts(ports []container.Port) string {
portKey := port.Type
if port.IP != "" {
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
}
portKey = port.IP + "/" + port.Type
Expand Down
10 changes: 10 additions & 0 deletions cli/command/formatter/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,16 @@ func TestDisplayablePorts(t *testing.T) {
},
expected: "0.0.0.0:0->9988/tcp",
},
{
ports: []container.Port{
{
IP: "::",
PrivatePort: 9988,
Type: "tcp",
},
},
expected: "[::]:0->9988/tcp",
},
{
ports: []container.Port{
{
Expand Down

0 comments on commit d47c36d

Please sign in to comment.