Skip to content

Commit 8a1c637

Browse files
committed
Fix setting HUGO_MODULE_PROXY etc. via env vars
Fixes #7903
1 parent 6d95dc9 commit 8a1c637

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

common/maps/params.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ func getNested(m map[string]interface{}, indices []string) (interface{}, string,
3737
first := indices[0]
3838
v, found := m[strings.ToLower(cast.ToString(first))]
3939
if !found {
40+
if len(indices) == 1 {
41+
return nil, first, m
42+
}
4043
return nil, "", nil
44+
4145
}
4246

4347
if len(indices) == 1 {

common/maps/params_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,29 @@ func TestGetNestedParam(t *testing.T) {
4747
c.Assert(must("nested_color", "_", m), qt.Equals, "blue")
4848
c.Assert(must("nested.nestednested.color", ".", m), qt.Equals, "green")
4949
c.Assert(must("string.name", ".", m), qt.IsNil)
50+
c.Assert(must("nested.foo", ".", m), qt.IsNil)
51+
52+
}
53+
54+
// https://github.com/gohugoio/hugo/issues/7903
55+
func TestGetNestedParamFnNestedNewKey(t *testing.T) {
56+
57+
c := qt.New(t)
58+
59+
nested := map[string]interface{}{
60+
"color": "blue",
61+
}
62+
m := map[string]interface{}{
63+
"nested": nested,
64+
}
65+
66+
existing, nestedKey, owner, err := GetNestedParamFn("nested.new", ".", func(key string) interface{} {
67+
return m[key]
68+
})
69+
70+
c.Assert(err, qt.IsNil)
71+
c.Assert(existing, qt.IsNil)
72+
c.Assert(nestedKey, qt.Equals, "new")
73+
c.Assert(owner, qt.DeepEquals, nested)
5074

5175
}

hugolib/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
198198
} else {
199199
v.Set(key, val)
200200
}
201+
} else if nestedKey != "" {
202+
owner[nestedKey] = valStr
201203
} else {
202204
v.Set(key, valStr)
203205
}

hugolib/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ stringSlice = ["a", "b"]
495495
[imaging]
496496
anchor = "smart"
497497
quality = 75
498-
resamplefilter = "CatmullRom"
499498
`
500499

501500
b := newTestSitesBuilder(t).WithConfigFile("toml", baseConfig)
@@ -505,6 +504,7 @@ resamplefilter = "CatmullRom"
505504
"HUGO_NEW", "new", // key not in config.toml
506505
"HUGO_ENABLEGITINFO", "false",
507506
"HUGO_IMAGING_ANCHOR", "top",
507+
"HUGO_IMAGING_RESAMPLEFILTER", "CatmullRom",
508508
"HUGO_STRINGSLICE", `["c", "d"]`,
509509
"HUGO_INTSLICE", `[5, 8, 9]`,
510510
"HUGO_FLOATSLICE", `[5.32]`,
@@ -519,6 +519,7 @@ resamplefilter = "CatmullRom"
519519
c.Assert(cfg.Get("new"), qt.Equals, "new")
520520
c.Assert(cfg.Get("imaging.anchor"), qt.Equals, "top")
521521
c.Assert(cfg.Get("imaging.quality"), qt.Equals, int64(75))
522+
c.Assert(cfg.Get("imaging.resamplefilter"), qt.Equals, "CatmullRom")
522523
c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []interface{}{"c", "d"})
523524
c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []interface{}{5.32})
524525
c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9})

0 commit comments

Comments
 (0)