From 98c1a412b4102deb3ff58dd035447dc5a9d23ce3 Mon Sep 17 00:00:00 2001 From: Shijiang Wei Date: Fri, 16 Oct 2015 22:09:32 +0800 Subject: [PATCH] make sure the value of the dangling filter is correct Signed-off-by: Shijiang Wei --- graph/list.go | 4 +++- integration-cli/docker_cli_images_test.go | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/graph/list.go b/graph/list.go index a45cce7d26..8110beed28 100644 --- a/graph/list.go +++ b/graph/list.go @@ -51,8 +51,10 @@ func (s *TagStore) Images(filterArgs, filter string, all bool) ([]*types.Image, if i, ok := imageFilters["dangling"]; ok { for _, value := range i { - if strings.ToLower(value) == "true" { + if v := strings.ToLower(value); v == "true" { filtTagged = false + } else if v != "false" { + return nil, fmt.Errorf("Invalid filter 'dangling=%s'", v) } } } diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index 04bbce5b0e..3f639a5a16 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/integration-cli/docker_cli_images_test.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "github.com/docker/docker/pkg/integration/checker" "github.com/docker/docker/pkg/stringid" "github.com/go-check/check" ) @@ -197,3 +198,9 @@ func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) { c.Fatalf("expected 1 dangling image, got %d: %s", a, out) } } + +func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) { + out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") + c.Assert(err, check.NotNil) + c.Assert(out, checker.Contains, "Invalid filter") +}