Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-30 11:56:45 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-30 22:07:52 +0300
commite3dc5240f01fd5ec67643e40f27c026d707da110 (patch)
treeb7558806edbdcfa86d2d73dea83c3455e11c7678 /common
parent268065cb2d8339392766a23703beaf7cc49d6b5c (diff)
Improve handling of <nil> Params
Fixes #8825
Diffstat (limited to 'common')
-rw-r--r--common/maps/maps.go6
-rw-r--r--common/maps/maps_test.go10
2 files changed, 16 insertions, 0 deletions
diff --git a/common/maps/maps.go b/common/maps/maps.go
index 79fcc23d0..b5e9ba2f5 100644
--- a/common/maps/maps.go
+++ b/common/maps/maps.go
@@ -17,6 +17,8 @@ import (
"fmt"
"strings"
+ "github.com/gohugoio/hugo/common/types"
+
"github.com/gobwas/glob"
"github.com/spf13/cast"
)
@@ -39,8 +41,12 @@ func ToStringMapE(in interface{}) (map[string]interface{}, error) {
}
// ToParamsAndPrepare converts in to Params and prepares it for use.
+// If in is nil, an empty map is returned.
// See PrepareParams.
func ToParamsAndPrepare(in interface{}) (Params, bool) {
+ if types.IsNil(in) {
+ return Params{}, true
+ }
m, err := ToStringMapE(in)
if err != nil {
return nil, false
diff --git a/common/maps/maps_test.go b/common/maps/maps_test.go
index ba3c25087..f0c32b9fe 100644
--- a/common/maps/maps_test.go
+++ b/common/maps/maps_test.go
@@ -114,6 +114,16 @@ func TestToSliceStringMap(t *testing.T) {
}
}
+func TestToParamsAndPrepare(t *testing.T) {
+ c := qt.New(t)
+ _, ok := ToParamsAndPrepare(map[string]interface{}{"A": "av"})
+ c.Assert(ok, qt.IsTrue)
+
+ params, ok := ToParamsAndPrepare(nil)
+ c.Assert(ok, qt.IsTrue)
+ c.Assert(params, qt.DeepEquals, Params{})
+}
+
func TestRenameKeys(t *testing.T) {
c := qt.New(t)