From 696c2d40d2343a0f168838d2ed277cf6df2d2082 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 25 Apr 2023 15:23:10 +0200 Subject: [PATCH] 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 --- pkg/api/handlers/compat/images.go | 23 +++++++++++++++++------ test/apiv2/10-images.at | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go index 34f721a882..4e5662c845 100644 --- a/pkg/api/handlers/compat/images.go +++ b/pkg/api/handlers/compat/images.go @@ -21,6 +21,7 @@ import ( "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/infra/abi" + "github.com/containers/podman/v4/pkg/util" "github.com/containers/storage" "github.com/docker/docker/pkg/jsonmessage" "github.com/gorilla/schema" @@ -431,12 +432,22 @@ func GetImages(w http.ResponseWriter, r *http.Request) { return } - filterList, err := filters.FiltersFromRequest(r) - if err != nil { - utils.Error(w, http.StatusInternalServerError, err) - return - } - if !utils.IsLibpodRequest(r) { + var filterList []string + var err error + if utils.IsLibpodRequest(r) { + // Podman clients split the filter map as `"{"label":["version","1.0"]}` + filterList, err = filters.FiltersFromRequest(r) + if err != nil { + utils.Error(w, http.StatusInternalServerError, err) + return + } + } else { + // Docker clients split the filter map as `"{"label":["version=1.0"]}` + filterList, err = util.FiltersFromRequest(r) + if err != nil { + utils.Error(w, http.StatusInternalServerError, err) + return + } if len(query.Filter) > 0 { // Docker 1.24 compatibility filterList = append(filterList, "reference="+query.Filter) } diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 733a56f448..5136328ba7 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -124,7 +124,7 @@ from alpine RUN >file1 EOF -podman image build -t test:test --label xyz -<file2 EOF @@ -134,7 +134,7 @@ t POST images/prune?filters='{"dangling":["true"]}' 200 t GET images/json?filters='{"dangling":["true"]}' 200 length=0 #label filter check in libpod and compat -t GET images/json?filters='{"label":["xyz"]}' 200 length=1 +t GET images/json?filters='{"label":["xyz","abc"]}' 200 length=1 t GET libpod/images/json?filters='{"label":["xyz"]}' 200 length=1 t DELETE libpod/images/test:test 200