From 1a1f9fac06496c6414d1dc57090962b57f6eff6c Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 27 Jul 2020 09:59:00 +0200 Subject: [PATCH 1/2] API events: fix parsing error Fix an error where an absent "filters" parameter led to JSON parsing errors. Fixes: #7078 Signed-off-by: Valentin Rothberg --- pkg/api/handlers/compat/events.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go index 9d5cb50450..8c4ad575b6 100644 --- a/pkg/api/handlers/compat/events.go +++ b/pkg/api/handlers/compat/events.go @@ -29,8 +29,14 @@ func filtersFromRequest(r *http.Request) ([]string, error) { compatFilters map[string]map[string]bool filters map[string][]string libpodFilters []string + raw []byte ) - raw := []byte(r.Form.Get("filters")) + + if _, found := r.URL.Query()["filters"]; found { + raw = []byte(r.Form.Get("filters")) + } else { + return []string{}, nil + } // Backwards compat with older versions of Docker. if err := json.Unmarshal(raw, &compatFilters); err == nil { From e2cb457e5fc1e45c84f380b5240b8cd5e9f76ce6 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 27 Jul 2020 11:46:19 +0200 Subject: [PATCH 2/2] test/apiv2: add a simple events test Add a simple test to exercise the events API without the "filters" parameter. Prevents regressing on #7078. Signed-off-by: Valentin Rothberg --- test/apiv2/01-basic.at | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/apiv2/01-basic.at b/test/apiv2/01-basic.at index 18ec9bbe80..79dac990a3 100644 --- a/test/apiv2/01-basic.at +++ b/test/apiv2/01-basic.at @@ -68,4 +68,8 @@ else _show_ok 0 "Time for ten /info requests" "<= 5 seconds" "$delta_t seconds" fi +# Simple events test (see #7078) +t GET "events?stream=false" 200 +t GET "libpod/events?stream=false" 200 + # vim: filetype=sh