Fix In func given an []interface{}
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 12 Oct 2015 15:58:40 +0000 (17:58 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 13 Oct 2015 15:05:36 +0000 (17:05 +0200)
Fixes #1486

tpl/template_funcs.go
tpl/template_funcs_test.go

index b92c2c955fc086886898494c6f9ee6b35ef5ce5f..f704f0a4fb94acfe470ae2591cd7393e54da6f12 100644 (file)
@@ -330,6 +330,10 @@ func In(l interface{}, v interface{}) bool {
        case reflect.Array, reflect.Slice:
                for i := 0; i < lv.Len(); i++ {
                        lvv := lv.Index(i)
+                       lvv, isNil := indirect(lvv)
+                       if isNil {
+                               continue
+                       }
                        switch lvv.Kind() {
                        case reflect.String:
                                if vv.Type() == lvv.Type() && vv.String() == lvv.String() {
index 6afb5eee47666e7661b768b53f750cc851c3419e..67e23c03093c525b2f4aec857a85a2ee5cd11c83 100644 (file)
@@ -354,9 +354,14 @@ func TestIn(t *testing.T) {
                expect bool
        }{
                {[]string{"a", "b", "c"}, "b", true},
+               {[]interface{}{"a", "b", "c"}, "b", true},
+               {[]interface{}{"a", "b", "c"}, "d", false},
                {[]string{"a", "b", "c"}, "d", false},
                {[]string{"a", "12", "c"}, 12, false},
                {[]int{1, 2, 4}, 2, true},
+               {[]interface{}{1, 2, 4}, 2, true},
+               {[]interface{}{1, 2, 4}, nil, false},
+               {[]interface{}{nil}, nil, false},
                {[]int{1, 2, 4}, 3, false},
                {[]float64{1.23, 2.45, 4.67}, 1.23, true},
                {[]float64{1.234567, 2.45, 4.67}, 1.234568, false},