mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
tpl/collections: Improve type handling in collections.Slice
Fixes #5188
This commit is contained in:
@@ -102,6 +102,23 @@ func convertNumber(v reflect.Value, to reflect.Kind) (reflect.Value, error) {
|
||||
|
||||
}
|
||||
|
||||
func newSliceElement(items interface{}) interface{} {
|
||||
tp := reflect.TypeOf(items)
|
||||
if tp == nil {
|
||||
return nil
|
||||
}
|
||||
switch tp.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
tp = tp.Elem()
|
||||
if tp.Kind() == reflect.Ptr {
|
||||
tp = tp.Elem()
|
||||
}
|
||||
|
||||
return reflect.New(tp).Interface()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isNumber(kind reflect.Kind) bool {
|
||||
return isInt(kind) || isUint(kind) || isFloat(kind)
|
||||
}
|
||||
|
Reference in New Issue
Block a user