Skip to content

Commit b5efd66

Browse files
committed
cli/command/container: stats: make stripping "/" prefix deterministic
This code was assuming the API always returns container names with a "/" prefix. While this is currently correct, we may at some point stop doing so. This patch changes the code to only trim "/" as prefix and not any other character. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7922984 commit b5efd66

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cli/command/container/formatter_stats.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package container
22

33
import (
44
"strconv"
5+
"strings"
56
"sync"
67

78
"github.com/docker/cli/cli/command/formatter"
@@ -167,9 +168,9 @@ func (c *statsContext) Container() string {
167168
}
168169

169170
func (c *statsContext) Name() string {
170-
// TODO(thaJeztah): make this explicitly trim the "/" prefix, not just any char.
171-
if len(c.s.Name) > 1 {
172-
return c.s.Name[1:]
171+
// Trim the "/" prefix (if present).
172+
if name := strings.TrimPrefix(c.s.Name, "/"); name != "" {
173+
return name
173174
}
174175
return noValue
175176
}

0 commit comments

Comments
 (0)