mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix for #8777
Now filter name is trimmed and lowercased before evaluation for case insensitive and whitespace trimemd check. Signed-off-by: Oh Jinkyun <tintypemolly@gmail.com>
This commit is contained in:
parent
739d917d70
commit
4deac03c65
3 changed files with 72 additions and 1 deletions
|
@ -47,6 +47,10 @@ const (
|
||||||
tarHeaderSize = 512
|
tarHeaderSize = 512
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
acceptedImageFilterTags = map[string]struct{}{"dangling": {}}
|
||||||
|
)
|
||||||
|
|
||||||
func (cli *DockerCli) CmdHelp(args ...string) error {
|
func (cli *DockerCli) CmdHelp(args ...string) error {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
method, exists := cli.getMethod(args[:2]...)
|
method, exists := cli.getMethod(args[:2]...)
|
||||||
|
@ -1336,6 +1340,12 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for name := range imageFilterArgs {
|
||||||
|
if _, ok := acceptedImageFilterTags[name]; !ok {
|
||||||
|
return fmt.Errorf("Invalid filter '%s'", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
matchName := cmd.Arg(0)
|
matchName := cmd.Arg(0)
|
||||||
// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
||||||
if *flViz || *flTree {
|
if *flViz || *flTree {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -63,3 +66,59 @@ func TestImagesOrderedByCreationDate(t *testing.T) {
|
||||||
|
|
||||||
logDone("images - ordering by creation date")
|
logDone("images - ordering by creation date")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImagesErrorWithInvalidFilterNameTest(t *testing.T) {
|
||||||
|
imagesCmd := exec.Command(dockerBinary, "images", "-f", "FOO=123")
|
||||||
|
out, _, err := runCommandWithOutput(imagesCmd)
|
||||||
|
if !strings.Contains(out, "Invalid filter") {
|
||||||
|
t.Fatalf("error should occur when listing images with invalid filter name FOO, %s, %v", out, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("images - invalid filter name check working")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestImagesFilterWhiteSpaceTrimmingAndLowerCasingWorking(t *testing.T) {
|
||||||
|
imageName := "images_filter_test"
|
||||||
|
defer deleteAllContainers()
|
||||||
|
defer deleteImages(imageName)
|
||||||
|
buildImage(imageName,
|
||||||
|
`FROM scratch
|
||||||
|
RUN touch /test/foo
|
||||||
|
RUN touch /test/bar
|
||||||
|
RUN touch /test/baz`, true)
|
||||||
|
|
||||||
|
filters := []string{
|
||||||
|
"dangling=true",
|
||||||
|
"Dangling=true",
|
||||||
|
" dangling=true",
|
||||||
|
"dangling=true ",
|
||||||
|
"dangling = true",
|
||||||
|
}
|
||||||
|
|
||||||
|
imageListings := make([][]string, 5, 5)
|
||||||
|
for idx, filter := range filters {
|
||||||
|
cmd := exec.Command(dockerBinary, "images", "-f", filter)
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
listing := strings.Split(out, "\n")
|
||||||
|
sort.Strings(listing)
|
||||||
|
imageListings[idx] = listing
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx, listing := range imageListings {
|
||||||
|
if idx < 4 && !reflect.DeepEqual(listing, imageListings[idx+1]) {
|
||||||
|
for idx, errListing := range imageListings {
|
||||||
|
fmt.Printf("out %d", idx)
|
||||||
|
for _, image := range errListing {
|
||||||
|
fmt.Print(image)
|
||||||
|
}
|
||||||
|
fmt.Print("")
|
||||||
|
}
|
||||||
|
t.Fatalf("All output must be the same")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("images - white space trimming and lower casing")
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,9 @@ func ParseFlag(arg string, prev Args) (Args, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f := strings.SplitN(arg, "=", 2)
|
f := strings.SplitN(arg, "=", 2)
|
||||||
filters[f[0]] = append(filters[f[0]], f[1])
|
name := strings.ToLower(strings.TrimSpace(f[0]))
|
||||||
|
value := strings.TrimSpace(f[1])
|
||||||
|
filters[name] = append(filters[name], value)
|
||||||
|
|
||||||
return filters, nil
|
return filters, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue