diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index eb6ecb9bbba..95079436fde 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -378,7 +378,7 @@ func (ns *Namespace) Last(limit interface{}, seq interface{}) (interface{}, erro return nil, err } - if limitv < 1 { + if limitv < 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 781f44e0a29..2c68a776617 100644 --- a/tpl/collections/collections_test.go +++ b/tpl/collections/collections_test.go @@ -495,6 +495,8 @@ func TestLast(t *testing.T) { {int64(2), []int{100, 200, 300}, []int{200, 300}}, {100, []int{100, 200}, []int{100, 200}}, {"1", []int{100, 200, 300}, []int{300}}, + {"0", []int{100, 200, 300}, []int{}}, + {"0", []string{"a", "b", "c"}, []string{}}, // errors {int64(-1), []int{100, 200, 300}, false}, {"noint", []int{100, 200, 300}, false},