aboutsummaryrefslogtreecommitdiffhomepage
path: root/common/maps
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-06-27 13:24:49 +0200
committerBjørn Erik Pedersen <[email protected]>2021-06-27 15:01:56 +0200
commit19aa95fc7f4cd58dcc8a8ff075762cfc86d41dc3 (patch)
tree59b96d8099fb7a18e7e55ba9a115163c9dea6043 /common/maps
parent923dd9d1c1f649142f3f377109318b07e0f44d5d (diff)
downloadhugo-19aa95fc7f4cd58dcc8a8ff075762cfc86d41dc3.tar.gz
hugo-19aa95fc7f4cd58dcc8a8ff075762cfc86d41dc3.zip
Fix config handling with empty config entries after merge
Fixes #8701
Diffstat (limited to 'common/maps')
-rw-r--r--common/maps/params.go21
-rw-r--r--common/maps/params_test.go12
2 files changed, 30 insertions, 3 deletions
diff --git a/common/maps/params.go b/common/maps/params.go
index e5a1bd07d..c14026df7 100644
--- a/common/maps/params.go
+++ b/common/maps/params.go
@@ -52,6 +52,24 @@ func (p Params) Set(pp Params) {
}
}
+// IsZero returns true if p is considered empty.
+func (p Params) IsZero() bool {
+ if p == nil || len(p) == 0 {
+ return true
+ }
+
+ if len(p) > 1 {
+ return false
+ }
+
+ for k, _ := range p {
+ return k == mergeStrategyKey
+ }
+
+ return false
+
+}
+
// Merge transfers values from pp to p for new keys.
// This is done recursively.
func (p Params) Merge(pp Params) {
@@ -82,12 +100,9 @@ func (p Params) merge(ps ParamsMergeStrategy, pp Params) {
if pv, ok := v.(Params); ok {
vvv.merge(ms, pv)
}
-
}
-
} else if !noUpdate {
p[k] = v
-
}
}
diff --git a/common/maps/params_test.go b/common/maps/params_test.go
index 8859bb86b..5c799aae1 100644
--- a/common/maps/params_test.go
+++ b/common/maps/params_test.go
@@ -156,3 +156,15 @@ func TestParamsSetAndMerge(t *testing.T) {
})
}
+
+func TestParamsIsZero(t *testing.T) {
+ c := qt.New(t)
+
+ var nilParams Params
+
+ c.Assert(Params{}.IsZero(), qt.IsTrue)
+ c.Assert(nilParams.IsZero(), qt.IsTrue)
+ c.Assert(Params{"foo": "bar"}.IsZero(), qt.IsFalse)
+ c.Assert(Params{"_merge": "foo", "foo": "bar"}.IsZero(), qt.IsFalse)
+ c.Assert(Params{"_merge": "foo"}.IsZero(), qt.IsTrue)
+}