mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
tpl/collections: Some more params merge adjustments
* If the end result is maps.Params, we need to lower the keys * Also make sure to handle nested maps of different type Update #6633
This commit is contained in:
committed by
GitHub
parent
a67d95fe1a
commit
ccb1bf1abb
@@ -17,6 +17,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
|
||||
"github.com/gohugoio/hugo/common/hreflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -68,6 +70,9 @@ func mergeMap(dst, src reflect.Value) reflect.Value {
|
||||
|
||||
out := reflect.MakeMap(dst.Type())
|
||||
|
||||
// If the destination is Params, we must lower case all keys.
|
||||
_, lowerCase := dst.Interface().(maps.Params)
|
||||
|
||||
// Copy the destination map.
|
||||
for _, key := range dst.MapKeys() {
|
||||
v := dst.MapIndex(key)
|
||||
@@ -81,15 +86,18 @@ func mergeMap(dst, src reflect.Value) reflect.Value {
|
||||
dv, found := caseInsensitiveLookup(dst, key)
|
||||
|
||||
if found {
|
||||
// If both are the same map type, merge.
|
||||
// If both are the same map key type, merge.
|
||||
dve := dv.Elem()
|
||||
if dve.Kind() == reflect.Map {
|
||||
sve := sv.Elem()
|
||||
if dve.Type() == sve.Type() {
|
||||
if dve.Type().Key() == sve.Type().Key() {
|
||||
out.SetMapIndex(key, mergeMap(dve, sve))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if lowerCase && key.Kind() == reflect.String {
|
||||
key = reflect.ValueOf(strings.ToLower(key.String()))
|
||||
}
|
||||
out.SetMapIndex(key, sv)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user