Skip to content

Commit 6f42cfb

Browse files
committed
Fix assignment to entry in nil map
Fixes #13853
1 parent a84beee commit 6f42cfb

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

hugolib/cascade_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,27 @@ All.
965965

966966
b.AssertLogContains("! WARN")
967967
}
968+
969+
func TestCascadeNilMapIssue13853(t *testing.T) {
970+
t.Parallel()
971+
972+
files := `
973+
-- hugo.toml --
974+
-- content/test/_index.md --
975+
---
976+
title: Test
977+
cascade:
978+
- build:
979+
list: local
980+
target:
981+
path: '{/test/**}'
982+
- params:
983+
title: 'Test page'
984+
target:
985+
path: '{/test/**}'
986+
---
987+
`
988+
989+
// Just verify that it does not panic.
990+
_ = Test(t, files)
991+
}

resources/page/page_matcher.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
177177
if pcfg.Fields == nil {
178178
pcfg.Fields = make(maps.Params)
179179
}
180+
if pcfg.Params == nil {
181+
pcfg.Params = make(maps.Params)
182+
}
180183
for k, v := range m {
181184
switch strings.ToLower(k) {
182185
case "_target", "target":
@@ -186,17 +189,13 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
186189
}
187190
pcfg.Target = target
188191
case "params":
189-
if pcfg.Params == nil {
190-
pcfg.Params = make(maps.Params)
191-
}
192192
params := maps.ToStringMap(v)
193193
for k, v := range params {
194194
if _, found := pcfg.Params[k]; !found {
195195
pcfg.Params[k] = v
196196
}
197197
}
198198
default:
199-
200199
pcfg.Fields[k] = v
201200
}
202201
}

resources/page/page_matcher_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func TestPageMatcher(t *testing.T) {
8989
return v
9090
}
9191
c.Assert(fn(map[string]any{"_target": map[string]any{"kind": "page"}, "foo": "bar"}), qt.DeepEquals, PageMatcherParamsConfig{
92+
Params: maps.Params{},
9293
Fields: maps.Params{
9394
"foo": "bar",
9495
},

0 commit comments

Comments
 (0)