Fix setting HUGO_MODULE_PROXY etc. via env vars
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 29 Oct 2020 15:22:35 +0000 (16:22 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 30 Oct 2020 08:41:04 +0000 (09:41 +0100)
Fixes #7903

common/maps/params.go
common/maps/params_test.go
hugolib/config.go
hugolib/config_test.go

index ecb63d7a5e56c45b2a6294b376eda8131a477918..1f0856598353748656574ba63192284dd1826d80 100644 (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 {
index 8016a8bd643df4792b78945539910a70beeb80ff..46d672d873f14f10cc241569e376f1e8f9fcf3ae 100644 (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)
 
 }
index 7500dfc729cf1c79511efa7217aeb9ff56a565ee..72b51272b5964fec4d88b6ea70656202744365d8 100644 (file)
@@ -198,6 +198,8 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
                                        } else {
                                                v.Set(key, val)
                                        }
+                               } else if nestedKey != "" {
+                                       owner[nestedKey] = valStr
                                } else {
                                        v.Set(key, valStr)
                                }
index a52e3f061c840afc7532008ae385b0b009b78f1e..cb9c1d8f62729175573592bbf5aefacefdc1585c 100644 (file)
@@ -495,7 +495,6 @@ stringSlice = ["a", "b"]
 [imaging]
 anchor = "smart"
 quality = 75 
-resamplefilter = "CatmullRom"
 `
 
        b := newTestSitesBuilder(t).WithConfigFile("toml", baseConfig)
@@ -505,6 +504,7 @@ resamplefilter = "CatmullRom"
                "HUGO_NEW", "new", // key not in config.toml
                "HUGO_ENABLEGITINFO", "false",
                "HUGO_IMAGING_ANCHOR", "top",
+               "HUGO_IMAGING_RESAMPLEFILTER", "CatmullRom",
                "HUGO_STRINGSLICE", `["c", "d"]`,
                "HUGO_INTSLICE", `[5, 8, 9]`,
                "HUGO_FLOATSLICE", `[5.32]`,
@@ -519,6 +519,7 @@ resamplefilter = "CatmullRom"
        c.Assert(cfg.Get("new"), qt.Equals, "new")
        c.Assert(cfg.Get("imaging.anchor"), qt.Equals, "top")
        c.Assert(cfg.Get("imaging.quality"), qt.Equals, int64(75))
+       c.Assert(cfg.Get("imaging.resamplefilter"), qt.Equals, "CatmullRom")
        c.Assert(cfg.Get("stringSlice"), qt.DeepEquals, []interface{}{"c", "d"})
        c.Assert(cfg.Get("floatSlice"), qt.DeepEquals, []interface{}{5.32})
        c.Assert(cfg.Get("intSlice"), qt.DeepEquals, []interface{}{5, 8, 9})