Skip to content

Commit

Permalink
Merge pull request containers#9892 from jwhonce/wip/top
Browse files Browse the repository at this point in the history
Trim white space from /top endpoint results
  • Loading branch information
openshift-merge-robot authored Mar 30, 2021
2 parents 989c8e9 + eef6697 commit bd07179
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pkg/api/handlers/compat/containers_top.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ func TopContainer(w http.ResponseWriter, r *http.Request) {
var body = handlers.ContainerTopOKBody{}
if len(output) > 0 {
body.Titles = strings.Split(output[0], "\t")
for i := range body.Titles {
body.Titles[i] = strings.TrimSpace(body.Titles[i])
}

for _, line := range output[1:] {
body.Processes = append(body.Processes, strings.Split(line, "\t"))
process := strings.Split(line, "\t")
for i := range process {
process[i] = strings.TrimSpace(process[i])
}
body.Processes = append(body.Processes, process)
}
}
utils.WriteJSON(w, http.StatusOK, body)
Expand Down
3 changes: 2 additions & 1 deletion test/apiv2/25-containersMore.at
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ t GET libpod/containers/foo/json 200 \

# List processes of the container
t GET libpod/containers/foo/top 200 \
length=2
length=2 \
.Processes[0][7]="top"

# List processes of none such
t GET libpod/containers/nonesuch/top 404
Expand Down

0 comments on commit bd07179

Please sign in to comment.