Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: fix parsing filters #18345

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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