Fix nested OS env config override when parent does not exist

Fixes #8618
This commit is contained in:
Bjørn Erik Pedersen 2021-06-08 09:48:22 +02:00
parent f55d2f4376
commit 12530519d8
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 6 additions and 1 deletions

View file

@ -221,7 +221,7 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
} else if nestedKey != "" { } else if nestedKey != "" {
owner[nestedKey] = env.Value owner[nestedKey] = env.Value
} else { } else {
v.Set(env.Key, env.Value) v.Set(strings.ReplaceAll(env.Key, delim, "."), env.Value)
} }
} }

View file

@ -530,11 +530,14 @@ theme_param="themevalue2"
"HUGOxPARAMSxMYTHEME_SECTION2xTHEME_PARAM", "themevalue2_changed", "HUGOxPARAMSxMYTHEME_SECTION2xTHEME_PARAM", "themevalue2_changed",
"HUGO_PARAMS_EMPTY", ``, "HUGO_PARAMS_EMPTY", ``,
"HUGO_PARAMS_HTML", `<a target="_blank" />`, "HUGO_PARAMS_HTML", `<a target="_blank" />`,
//
"HUGO_SERVICES_GOOGLEANALYTICS_ID", `gaid`,
) )
b.Build(BuildCfg{}) b.Build(BuildCfg{})
cfg := b.H.Cfg cfg := b.H.Cfg
scfg := b.H.Sites[0].siteConfigConfig.Services
c.Assert(cfg.Get("environment"), qt.Equals, "test") c.Assert(cfg.Get("environment"), qt.Equals, "test")
c.Assert(cfg.GetBool("enablegitinfo"), qt.Equals, false) c.Assert(cfg.GetBool("enablegitinfo"), qt.Equals, false)
@ -551,4 +554,6 @@ theme_param="themevalue2"
c.Assert(cfg.Get("params.mytheme_section2.theme_param"), qt.Equals, "themevalue2_changed") c.Assert(cfg.Get("params.mytheme_section2.theme_param"), qt.Equals, "themevalue2_changed")
c.Assert(cfg.Get("params.empty"), qt.Equals, ``) c.Assert(cfg.Get("params.empty"), qt.Equals, ``)
c.Assert(cfg.Get("params.html"), qt.Equals, `<a target="_blank" />`) c.Assert(cfg.Get("params.html"), qt.Equals, `<a target="_blank" />`)
c.Assert(scfg.GoogleAnalytics.ID, qt.Equals, "gaid")
} }