mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
tpl/collections: Allow first function to return an empty slice
Fixes #5235
This commit is contained in:
parent
4f9c109dc5
commit
cae07ce84b
3 changed files with 5 additions and 2 deletions
|
@ -25,3 +25,5 @@ aliases: []
|
|||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
*Note: Exclusive to `first`, LIMIT can be '0' to return an empty array.*
|
||||
|
|
|
@ -215,8 +215,8 @@ func (ns *Namespace) First(limit interface{}, seq interface{}) (interface{}, err
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if limitv < 1 {
|
||||
return nil, errors.New("can't return negative/empty count of items from sequence")
|
||||
if limitv < 0 {
|
||||
return nil, errors.New("can't return negative count of items from sequence")
|
||||
}
|
||||
|
||||
seqv := reflect.ValueOf(seq)
|
||||
|
|
|
@ -256,6 +256,7 @@ func TestFirst(t *testing.T) {
|
|||
{int64(2), []int{100, 200, 300}, []int{100, 200}},
|
||||
{100, []int{100, 200}, []int{100, 200}},
|
||||
{"1", []int{100, 200, 300}, []int{100}},
|
||||
{0, []string{"h", "u", "g", "o"}, []string{}},
|
||||
{int64(-1), []int{100, 200, 300}, false},
|
||||
{"noint", []int{100, 200, 300}, false},
|
||||
{1, nil, false},
|
||||
|
|
Loading…
Reference in a new issue