summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCameron Moore <moorereason@gmail.com>2016-03-13 16:39:03 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-03-17 20:09:43 +0100
commitdf44b1930a8b5be8959a808fc788a42c6b0166bb (patch)
tree759ad0bf2959a5c2ddd886239a5a0b119803eedc
parent600558273e34215098664290c3364d5291cdb77a (diff)
tpl: Send actual values to in from intersect
The `intersect` function uses `in` to avoid adding duplicates to the resulting set. We were passing `reflect.Value` items when we should have been using `Value.Interface()` to send the actual data structure. This fixes that. See #1952
-rw-r--r--tpl/template_funcs.go6
-rw-r--r--tpl/template_funcs_test.go2
2 files changed, 4 insertions, 4 deletions
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
index b4a737fae..b7d009520 100644
--- a/tpl/template_funcs.go
+++ b/tpl/template_funcs.go
@@ -330,20 +330,20 @@ func intersect(l1, l2 interface{}) (interface{}, error) {
l2vv := l2v.Index(j)
switch l1vv.Kind() {
case reflect.String:
- if l1vv.Type() == l2vv.Type() && l1vv.String() == l2vv.String() && !in(r, l2vv) {
+ if l1vv.Type() == l2vv.Type() && l1vv.String() == l2vv.String() && !in(r.Interface(), l2vv.Interface()) {
r = reflect.Append(r, l2vv)
}
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
switch l2vv.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- if l1vv.Int() == l2vv.Int() && !in(r, l2vv) {
+ if l1vv.Int() == l2vv.Int() && !in(r.Interface(), l2vv.Interface()) {
r = reflect.Append(r, l2vv)
}
}
case reflect.Float32, reflect.Float64:
switch l2vv.Kind() {
case reflect.Float32, reflect.Float64:
- if l1vv.Float() == l2vv.Float() && !in(r, l2vv) {
+ if l1vv.Float() == l2vv.Float() && !in(r.Interface(), l2vv.Interface()) {
r = reflect.Append(r, l2vv)
}
}
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
index 28b18c927..a6a284bbf 100644
--- a/tpl/template_funcs_test.go
+++ b/tpl/template_funcs_test.go
@@ -776,7 +776,7 @@ func TestIntersect(t *testing.T) {
sequence2 interface{}
expect interface{}
}{
- {[]string{"a", "b", "c"}, []string{"a", "b"}, []string{"a", "b"}},
+ {[]string{"a", "b", "c", "c"}, []string{"a", "b", "b"}, []string{"a", "b"}},
{[]string{"a", "b"}, []string{"a", "b", "c"}, []string{"a", "b"}},
{[]string{"a", "b", "c"}, []string{"d", "e"}, []string{}},
{[]string{}, []string{}, []string{}},