Skip to content

Commit 9d478be

Browse files
authored
Merge pull request #5468 from akerouanton/fix-ps-ipv6
cli/formatter: fix unbracketed IPv6 addrs
2 parents 66977d4 + 3e27146 commit 9d478be

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

cli/command/formatter/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func formGroup(key string, start, last uint16) string {
377377
group = fmt.Sprintf("%s-%d", group, last)
378378
}
379379
if ip != "" {
380-
group = fmt.Sprintf("%s:%s->%s", ip, group, group)
380+
group = fmt.Sprintf("%s->%s", net.JoinHostPort(ip, group), group)
381381
}
382382
return group + "/" + groupType
383383
}

cli/command/formatter/container_test.go

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,17 @@ func TestDisplayablePorts(t *testing.T) {
589589
},
590590
expected: "4.3.2.1:8899->9988/tcp",
591591
},
592+
{
593+
ports: []container.Port{
594+
{
595+
IP: "::1",
596+
PrivatePort: 9988,
597+
PublicPort: 8899,
598+
Type: "tcp",
599+
},
600+
},
601+
expected: "[::1]:8899->9988/tcp",
602+
},
592603
{
593604
ports: []container.Port{
594605
{
@@ -600,6 +611,17 @@ func TestDisplayablePorts(t *testing.T) {
600611
},
601612
expected: "4.3.2.1:9988->9988/tcp",
602613
},
614+
{
615+
ports: []container.Port{
616+
{
617+
IP: "::1",
618+
PrivatePort: 9988,
619+
PublicPort: 9988,
620+
Type: "tcp",
621+
},
622+
},
623+
expected: "[::1]:9988->9988/tcp",
624+
},
603625
{
604626
ports: []container.Port{
605627
{
@@ -628,6 +650,22 @@ func TestDisplayablePorts(t *testing.T) {
628650
},
629651
expected: "1.2.3.4:9998-9999->9998-9999/udp",
630652
},
653+
{
654+
ports: []container.Port{
655+
{
656+
IP: "::1",
657+
PublicPort: 9998,
658+
PrivatePort: 9998,
659+
Type: "udp",
660+
}, {
661+
IP: "::1",
662+
PublicPort: 9999,
663+
PrivatePort: 9999,
664+
Type: "udp",
665+
},
666+
},
667+
expected: "[::1]:9998-9999->9998-9999/udp",
668+
},
631669
{
632670
ports: []container.Port{
633671
{
@@ -644,6 +682,22 @@ func TestDisplayablePorts(t *testing.T) {
644682
},
645683
expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp",
646684
},
685+
{
686+
ports: []container.Port{
687+
{
688+
IP: "::1",
689+
PublicPort: 8887,
690+
PrivatePort: 9998,
691+
Type: "udp",
692+
}, {
693+
IP: "::1",
694+
PublicPort: 8888,
695+
PrivatePort: 9999,
696+
Type: "udp",
697+
},
698+
},
699+
expected: "[::1]:8887->9998/udp, [::1]:8888->9999/udp",
700+
},
647701
{
648702
ports: []container.Port{
649703
{
@@ -688,9 +742,14 @@ func TestDisplayablePorts(t *testing.T) {
688742
PrivatePort: 2233,
689743
PublicPort: 3322,
690744
Type: "tcp",
745+
}, {
746+
IP: "::1",
747+
PrivatePort: 2233,
748+
PublicPort: 3322,
749+
Type: "tcp",
691750
},
692751
},
693-
expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
752+
expected: "4.3.2.1:3322->2233/tcp, [::1]:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
694753
},
695754
{
696755
ports: []container.Port{

0 commit comments

Comments
 (0)