14287: Fix accepting nil as filter operand.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 7 May 2019 13:40:47 +0000 (09:40 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 17 Jun 2019 13:54:39 +0000 (09:54 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

sdk/go/arvados/resource_list.go
sdk/go/arvados/resource_list_test.go

index 505ba51ec531387cffe71c8f7b179f436a6d9b75..d1a25c438a9eeb72e147cbd5658ee1bb340ee344 100644 (file)
@@ -55,7 +55,7 @@ func (f *Filter) UnmarshalJSON(data []byte) error {
        }
        operand := elements[2]
        switch operand.(type) {
        }
        operand := elements[2]
        switch operand.(type) {
-       case string, float64, []interface{}:
+       case string, float64, []interface{}, nil:
        default:
                return fmt.Errorf("invalid filter operand %q", elements[2])
        }
        default:
                return fmt.Errorf("invalid filter operand %q", elements[2])
        }
index 5642599b4c5664a16a7b1342887748863f9c2715..4e09c5375db980c60171f9209714c81f55aef152 100644 (file)
@@ -23,3 +23,14 @@ func TestMarshalFiltersWithNanoseconds(t *testing.T) {
                t.Errorf("Encoded as %q, expected %q", buf, expect)
        }
 }
                t.Errorf("Encoded as %q, expected %q", buf, expect)
        }
 }
+
+func TestMarshalFiltersWithNil(t *testing.T) {
+       buf, err := json.Marshal([]Filter{
+               {Attr: "modified_at", Operator: "=", Operand: nil}})
+       if err != nil {
+               t.Fatal(err)
+       }
+       if expect := []byte(`[["modified_at","=",null]]`); 0 != bytes.Compare(buf, expect) {
+               t.Errorf("Encoded as %q, expected %q", buf, expect)
+       }
+}