mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
tpl/collections: Unwrap any interface value in sort and where
Hugo `0.55.0` introduced some new interface types for `Page` etc. This worked great in general, but there were cases where this would fail in `where` and `sort`. One such example would be sorting by `MenuItem.Page.Date` where `Page` on `MenuItem` was a small subset of the bigger `page.Page` interface. This commit fixes that by unwrapping such interface values. Fixes #5989
This commit is contained in:
@@ -280,8 +280,16 @@ func evaluateSubElem(obj reflect.Value, elemName string) (reflect.Value, error)
|
||||
typ := obj.Type()
|
||||
obj, isNil := indirect(obj)
|
||||
|
||||
if obj.Kind() == reflect.Interface {
|
||||
// If obj is an interface, we need to inspect the value it contains
|
||||
// to see the full set of methods and fields.
|
||||
// Indirect returns the value that it points to, which is what's needed
|
||||
// below to be able to reflect on its fields.
|
||||
obj = reflect.Indirect(obj.Elem())
|
||||
}
|
||||
|
||||
// first, check whether obj has a method. In this case, obj is
|
||||
// an interface, a struct or its pointer. If obj is a struct,
|
||||
// a struct or its pointer. If obj is a struct,
|
||||
// to check all T and *T method, use obj pointer type Value
|
||||
objPtr := obj
|
||||
if objPtr.Kind() != reflect.Interface && objPtr.CanAddr() {
|
||||
|
Reference in New Issue
Block a user