From: Baibhav Vatsa Date: Fri, 11 Oct 2019 01:16:15 +0000 (-0500) Subject: tpl: After now accepts 0 as index X-Git-Tag: v0.59.0~19 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=096a4b67b98259dabff5ebfbfd879a41999a1ed2;p=brevno-suite%2Fhugo tpl: After now accepts 0 as index Modified the if conditional because of which after threw an error if called with 0 as index. The function now returns the whole original slice if 0 is passed as an index. Also added tests to test the new behavior. Fixes #6388 --- diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 19519987..eb6ecb9b 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -60,7 +60,7 @@ func (ns *Namespace) After(index interface{}, seq interface{}) (interface{}, err return nil, err } - if indexv < 1 { + if indexv < 0 { return nil, errors.New("can't return negative/empty count of items from sequence") } diff --git a/tpl/collections/collections_test.go b/tpl/collections/collections_test.go index 8ea973f0..781f44e0 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -50,6 +50,8 @@ func TestAfter(t *testing.T) { {int64(2), []int{100, 200, 300}, []int{300}}, {100, []int{100, 200}, []int{}}, {"1", []int{100, 200, 300}, []int{200, 300}}, + {0, []int{100, 200, 300, 400, 500}, []int{100, 200, 300, 400, 500}}, + {0, []string{"a", "b", "c", "d", "e"}, []string{"a", "b", "c", "d", "e"}}, {int64(-1), []int{100, 200, 300}, false}, {"noint", []int{100, 200, 300}, false}, {2, []string{}, []string{}},