mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-25 08:02:08 +00:00
tpl: Fix panic in sort of nil sequence
Properly handle a nil sequence in the sortSeq function. Test included. Discovered while using `range sort .Site.Data.source.Undefined "foo"`.
This commit is contained in:
parent
d15fda5000
commit
fe929114d3
2 changed files with 5 additions and 0 deletions
|
@ -957,6 +957,10 @@ func delimit(seq, delimiter interface{}, last ...interface{}) (template.HTML, er
|
|||
|
||||
// sortSeq returns a sorted sequence.
|
||||
func sortSeq(seq interface{}, args ...interface{}) (interface{}, error) {
|
||||
if seq == nil {
|
||||
return nil, errors.New("sequence must be provided")
|
||||
}
|
||||
|
||||
seqv := reflect.ValueOf(seq)
|
||||
seqv, isNil := indirect(seqv)
|
||||
if isNil {
|
||||
|
|
|
@ -1565,6 +1565,7 @@ func TestSort(t *testing.T) {
|
|||
"asc",
|
||||
false,
|
||||
},
|
||||
{nil, nil, "asc", false},
|
||||
} {
|
||||
var result interface{}
|
||||
var err error
|
||||
|
|
Loading…
Reference in a new issue