Skip to content

Commit 55d0b89

Browse files
moorereasonbep
authored andcommitted
tpl/collections: Fix intersect on []interface{} handling
Fixes #3718
1 parent aee2b06 commit 55d0b89

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎tpl/collections/where.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
5353
if !v.IsValid() {
5454
vIsNil = true
5555
}
56+
5657
mv, mvIsNil := indirect(mv)
5758
if !mv.IsValid() {
5859
mvIsNil = true
@@ -115,7 +116,7 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
115116
return false, nil
116117
}
117118

118-
if v.Kind() != reflect.Interface && mv.Type().Elem().Kind() != reflect.Interface && mv.Type().Elem() != v.Type() {
119+
if v.Kind() != reflect.Interface && mv.Type().Elem().Kind() != reflect.Interface && mv.Type().Elem() != v.Type() && v.Kind() != reflect.Array && v.Kind() != reflect.Slice {
119120
return false, nil
120121
}
121122
switch v.Kind() {
@@ -144,6 +145,9 @@ func (ns *Namespace) checkCondition(v, mv reflect.Value, op string) (bool, error
144145
ima = append(ima, toTimeUnix(mv.Index(i)))
145146
}
146147
}
148+
case reflect.Array, reflect.Slice:
149+
slv = v.Interface()
150+
slmv = mv.Interface()
147151
}
148152
}
149153

‎tpl/collections/where_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ func TestCheckCondition(t *testing.T) {
536536
{reflect.ValueOf(true), reflect.ValueOf(false), ">", expect{false, false}},
537537
{reflect.ValueOf(123), reflect.ValueOf([]int{}), "in", expect{false, false}},
538538
{reflect.ValueOf(123), reflect.ValueOf(123), "op", expect{false, true}},
539+
540+
// Issue #3718
541+
{reflect.ValueOf([]interface{}{"a"}), reflect.ValueOf([]string{"a", "b"}), "intersect", expect{true, false}},
542+
{reflect.ValueOf([]string{"a"}), reflect.ValueOf([]interface{}{"a", "b"}), "intersect", expect{true, false}},
543+
{reflect.ValueOf([]interface{}{1, 2}), reflect.ValueOf([]int{1}), "intersect", expect{true, false}},
544+
{reflect.ValueOf([]int{1}), reflect.ValueOf([]interface{}{1, 2}), "intersect", expect{true, false}},
539545
} {
540546
result, err := ns.checkCondition(test.value, test.match, test.op)
541547
if test.expect.isError {

0 commit comments

Comments
 (0)