shithub: hugo

Download patch

ref: 8a1c637c4494751046142e0ef345fce38fc1431b
parent: 6d95dc9d74681cba53b46e79c6e1d58d27fcdfb0
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Thu Oct 29 12:22:35 EDT 2020

Fix setting HUGO_MODULE_PROXY etc. via env vars

Fixes #7903

--- a/common/maps/params.go
+++ b/common/maps/params.go
@@ -37,7 +37,11 @@
 	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 {
--- a/common/maps/params_test.go
+++ b/common/maps/params_test.go
@@ -47,5 +47,29 @@
 	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)
 
 }
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -198,6 +198,8 @@
 					} else {
 						v.Set(key, val)
 					}
+				} else if nestedKey != "" {
+					owner[nestedKey] = valStr
 				} else {
 					v.Set(key, valStr)
 				}
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -495,7 +495,6 @@
 [imaging]
 anchor = "smart"
 quality = 75 
-resamplefilter = "CatmullRom"
 `
 
 	b := newTestSitesBuilder(t).WithConfigFile("toml", baseConfig)
@@ -505,6 +504,7 @@
 		"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 @@
 	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})