Skip to content

Commit

Permalink
Merge pull request #18345 from vrothberg/fix-18092
Browse files Browse the repository at this point in the history
api: fix parsing filters
  • Loading branch information
openshift-merge-robot authored May 2, 2023
2 parents 09c11a8 + 1720042 commit 0851d64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 17 additions & 6 deletions pkg/api/handlers/compat/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions test/apiv2/10-images.at
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ from alpine
RUN >file1
EOF

podman image build -t test:test --label xyz -<<EOF
podman image build -t test:test --label xyz --label abc -<<EOF
from alpine
RUN >file2
EOF
Expand All @@ -143,7 +143,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
Expand Down

0 comments on commit 0851d64

Please sign in to comment.