hugo

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

git clone git://git.shimmy1996.com/hugo.git
commit 7a97d3e6bca1e30826e1662b5f299b66aa8ab385
parent 6667c6d7430acc16b3683fbbacd263f1d00c8672
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Sat,  8 Sep 2018 21:56:36 +0200

tpl/collections: Allow pointer receiver in Group

See #4865

Diffstat:
Mtpl/collections/collections.go | 2+-
Mtpl/collections/collections_test.go | 10++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go
@@ -326,7 +326,7 @@ func (ns *Namespace) Group(key interface{}, items interface{}) (interface{}, err
 		if tp.Kind() == reflect.Ptr {
 			tp = tp.Elem()
 		}
-		in := reflect.Zero(tp).Interface()
+		in := reflect.New(tp).Interface()
 		switch vv := in.(type) {
 		case collections.Grouper:
 			return vv.Group(key, items)
diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go
@@ -85,6 +85,14 @@ func (g tstGrouper) Group(key interface{}, items interface{}) (interface{}, erro
 	return fmt.Sprintf("%v(%d)", key, ilen), nil
 }
 
+type tstGrouper2 struct {
+}
+
+func (g *tstGrouper2) Group(key interface{}, items interface{}) (interface{}, error) {
+	ilen := reflect.ValueOf(items).Len()
+	return fmt.Sprintf("%v(%d)", key, ilen), nil
+}
+
 func TestGroup(t *testing.T) {
 	t.Parallel()
 
@@ -98,6 +106,8 @@ func TestGroup(t *testing.T) {
 		{"a", []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, "a(2)"},
 		{"b", tstGroupers{&tstGrouper{}, &tstGrouper{}}, "b(2)"},
 		{"a", []tstGrouper{tstGrouper{}, tstGrouper{}}, "a(2)"},
+		{"a", []*tstGrouper2{&tstGrouper2{}, &tstGrouper2{}}, "a(2)"},
+		{"b", []tstGrouper2{tstGrouper2{}, tstGrouper2{}}, "b(2)"},
 		{"a", []*tstGrouper{}, "a(0)"},
 		{"a", []string{"a", "b"}, false},
 		{nil, []*tstGrouper{&tstGrouper{}, &tstGrouper{}}, false},