summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2017-07-27 17:23:49 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-07-28 07:21:21 +0200
commit55d0b89417651eba3ae51c96bd9de9e0daa0399e (patch)
tree7b22e4a6a3041e98de679bd3cfd1047c99758721 /tpl
parentaee2b06780858c12d8cb04c7b1ba592543410aa9 (diff)
tpl/collections: Fix intersect on []interface{} handling
Fixes #3718
Diffstat (limited to 'tpl')
-rw-r--r--tpl/collections/where.go6
-rw-r--r--tpl/collections/where_test.go6
2 files changed, 11 insertions, 1 deletions
diff --git a/tpl/collections/where.go b/tpl/collections/where.go
index 37be00509..be5c8205b 100644
--- a/tpl/collections/where.go
+++ b/tpl/collections/where.go
@@ -53,6 +53,7 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
if !v.IsValid() {
vIsNil = true
}
+
mv, mvIsNil := indirect(mv)
if !mv.IsValid() {
mvIsNil = true
@@ -115,7 +116,7 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
return false, nil
}
- if v.Kind() != reflect.Interface && mv.Type().Elem().Kind() != reflect.Interface && mv.Type().Elem() != v.Type() {
+ if v.Kind() != reflect.Interface && mv.Type().Elem().Kind() != reflect.Interface && mv.Type().Elem() != v.Type() && v.Kind() != reflect.Array && v.Kind() != reflect.Slice {
return false, nil
}
switch v.Kind() {
@@ -144,6 +145,9 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
ima = append(ima, toTimeUnix(mv.Index(i)))
}
}
+ case reflect.Array, reflect.Slice:
+ slv = v.Interface()
+ slmv = mv.Interface()
}
}
diff --git a/tpl/collections/where_test.go b/tpl/collections/where_test.go
index 771fafb61..e70283778 100644
--- a/tpl/collections/where_test.go
+++ b/tpl/collections/where_test.go
@@ -536,6 +536,12 @@ func TestCheckCondition(t *testing.T) {
{reflect.ValueOf(true), reflect.ValueOf(false), ">", expect{false, false}},
{reflect.ValueOf(123), reflect.ValueOf([]int{}), "in", expect{false, false}},
{reflect.ValueOf(123), reflect.ValueOf(123), "op", expect{false, true}},
+
+ // Issue #3718
+ {reflect.ValueOf([]interface{}{"a"}), reflect.ValueOf([]string{"a", "b"}), "intersect", expect{true, false}},
+ {reflect.ValueOf([]string{"a"}), reflect.ValueOf([]interface{}{"a", "b"}), "intersect", expect{true, false}},
+ {reflect.ValueOf([]interface{}{1, 2}), reflect.ValueOf([]int{1}), "intersect", expect{true, false}},
+ {reflect.ValueOf([]int{1}), reflect.ValueOf([]interface{}{1, 2}), "intersect", expect{true, false}},
} {
result, err := ns.checkCondition(test.value, test.match, test.op)
if test.expect.isError {