hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 4c04d7101add03f85b770b8bf7ee3fd3398cb7c0
parent ddd8c77938e20ee4d43c98704197d9b63a903b32
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Mon, 12 Oct 2015 17:58:40 +0200

Fix In func given an []interface{}

Fixes #1486

Diffstat:
Mtpl/template_funcs.go | 4++++
Mtpl/template_funcs_test.go | 5+++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
@@ -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() {
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
@@ -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},