Skip to content

Commit 36f6f98

Browse files
committed
resources/page: Make sure a map is always initialized
Fixes #13810
1 parent 18a9ca7 commit 36f6f98

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

resources/page/page_matcher.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ func DecodeCascade(logger loggers.Logger, handleLegacyFormat bool, in any) (*map
174174

175175
func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, error) {
176176
var pcfg PageMatcherParamsConfig
177+
if pcfg.Fields == nil {
178+
pcfg.Fields = make(maps.Params)
179+
}
177180
for k, v := range m {
178181
switch strings.ToLower(k) {
179182
case "_target", "target":
@@ -193,9 +196,6 @@ func mapToPageMatcherParamsConfig(m map[string]any) (PageMatcherParamsConfig, er
193196
}
194197
}
195198
default:
196-
if pcfg.Fields == nil {
197-
pcfg.Fields = make(maps.Params)
198-
}
199199

200200
pcfg.Fields[k] = v
201201
}

resources/page/page_matcher_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func TestPageMatcher(t *testing.T) {
9999
Params: maps.Params{
100100
"foo": "bar",
101101
},
102+
Fields: maps.Params{},
102103
Target: PageMatcher{Path: "", Kind: "page", Lang: "", Environment: ""},
103104
})
104105
})
@@ -136,9 +137,10 @@ func TestDecodeCascadeConfig(t *testing.T) {
136137
c.Assert(got.SourceStructure, qt.DeepEquals, []PageMatcherParamsConfig{
137138
{
138139
Params: maps.Params{"a": string("av")},
140+
Fields: maps.Params{},
139141
Target: PageMatcher{Kind: "page", Environment: "production"},
140142
},
141-
{Params: maps.Params{"b": string("bv")}, Target: PageMatcher{Kind: "page"}},
143+
{Params: maps.Params{"b": string("bv")}, Fields: maps.Params{}, Target: PageMatcher{Kind: "page"}},
142144
})
143145

144146
got, err = DecodeCascadeConfig(loggers.NewDefault(), true, nil)

0 commit comments

Comments
 (0)