Skip to content

Commit 1720042

Browse files
committed
api: fix parsing filters
Podman and Docker clients split the filter map slightly different, so account for that when parsing the filters in the image-listing endpoint. Fixes: #18092 Signed-off-by: Valentin Rothberg <[email protected]>
1 parent 91da62d commit 1720042

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

pkg/api/handlers/compat/images.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/containers/podman/v4/pkg/auth"
2222
"github.com/containers/podman/v4/pkg/domain/entities"
2323
"github.com/containers/podman/v4/pkg/domain/infra/abi"
24+
"github.com/containers/podman/v4/pkg/util"
2425
"github.com/containers/storage"
2526
"github.com/docker/docker/pkg/jsonmessage"
2627
"github.com/gorilla/schema"
@@ -431,12 +432,22 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
431432
return
432433
}
433434

434-
filterList, err := filters.FiltersFromRequest(r)
435-
if err != nil {
436-
utils.Error(w, http.StatusInternalServerError, err)
437-
return
438-
}
439-
if !utils.IsLibpodRequest(r) {
435+
var filterList []string
436+
var err error
437+
if utils.IsLibpodRequest(r) {
438+
// Podman clients split the filter map as `"{"label":["version","1.0"]}`
439+
filterList, err = filters.FiltersFromRequest(r)
440+
if err != nil {
441+
utils.Error(w, http.StatusInternalServerError, err)
442+
return
443+
}
444+
} else {
445+
// Docker clients split the filter map as `"{"label":["version=1.0"]}`
446+
filterList, err = util.FiltersFromRequest(r)
447+
if err != nil {
448+
utils.Error(w, http.StatusInternalServerError, err)
449+
return
450+
}
440451
if len(query.Filter) > 0 { // Docker 1.24 compatibility
441452
filterList = append(filterList, "reference="+query.Filter)
442453
}

test/apiv2/10-images.at

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ from alpine
133133
RUN >file1
134134
EOF
135135

136-
podman image build -t test:test --label xyz -<<EOF
136+
podman image build -t test:test --label xyz --label abc -<<EOF
137137
from alpine
138138
RUN >file2
139139
EOF
@@ -143,7 +143,7 @@ t POST images/prune?filters='{"dangling":["true"]}' 200
143143
t GET images/json?filters='{"dangling":["true"]}' 200 length=0
144144

145145
#label filter check in libpod and compat
146-
t GET images/json?filters='{"label":["xyz"]}' 200 length=1
146+
t GET images/json?filters='{"label":["xyz","abc"]}' 200 length=1
147147
t GET libpod/images/json?filters='{"label":["xyz"]}' 200 length=1
148148

149149
t DELETE libpod/images/test:test 200

0 commit comments

Comments
 (0)