Fix setting HUGO_MODULE_PROXY etc. via env vars

Fixes #7903
This commit is contained in:
Bjørn Erik Pedersen
2020-10-29 16:22:35 +01:00
parent 6d95dc9d74
commit 8a1c637c44
4 changed files with 32 additions and 1 deletions

View File

@@ -37,7 +37,11 @@ func getNested(m map[string]interface{}, indices []string) (interface{}, string,
first := indices[0]
v, found := m[strings.ToLower(cast.ToString(first))]
if !found {
if len(indices) == 1 {
return nil, first, m
}
return nil, "", nil
}
if len(indices) == 1 {

View File

@@ -47,5 +47,29 @@ func TestGetNestedParam(t *testing.T) {
c.Assert(must("nested_color", "_", m), qt.Equals, "blue")
c.Assert(must("nested.nestednested.color", ".", m), qt.Equals, "green")
c.Assert(must("string.name", ".", m), qt.IsNil)
c.Assert(must("nested.foo", ".", m), qt.IsNil)
}
// https://github.com/gohugoio/hugo/issues/7903
func TestGetNestedParamFnNestedNewKey(t *testing.T) {
c := qt.New(t)
nested := map[string]interface{}{
"color": "blue",
}
m := map[string]interface{}{
"nested": nested,
}
existing, nestedKey, owner, err := GetNestedParamFn("nested.new", ".", func(key string) interface{} {
return m[key]
})
c.Assert(err, qt.IsNil)
c.Assert(existing, qt.IsNil)
c.Assert(nestedKey, qt.Equals, "new")
c.Assert(owner, qt.DeepEquals, nested)
}