Run of fresh-snapshots for golang-github-mitchellh-reflectwalk

Try this locally (using silver-platter):

debian-svp new-upstream --snapshot golang-github-mitchellh-reflectwalk 

Merge these changes:

Summary

Merged new upstream version: 1.0.1 (was: 0.0~git20170726.63d60e9).

Diff

diff --git a/debian/changelog b/debian/changelog
index cb4ee20..708ad19 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-mitchellh-reflectwalk (1.0.1-1) UNRELEASED; urgency=medium
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Sun, 26 Jan 2020 19:38:36 +0000
+
 golang-github-mitchellh-reflectwalk (0.0~git20170726.63d60e9-4) unstable; urgency=medium
 
   * Team upload.
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..52bb7c4
--- /dev/null
+++ b/go.mod
@@ -0,0 +1 @@
+module github.com/mitchellh/reflectwalk
diff --git a/reflectwalk.go b/reflectwalk.go
index d7ab7b6..3a93a0b 100644
--- a/reflectwalk.go
+++ b/reflectwalk.go
@@ -230,7 +230,8 @@ func walkMap(v reflect.Value, w interface{}) error {
 			ew.Enter(MapValue)
 		}
 
-		if err := walk(kv, w); err != nil {
+		// get the map value again as it may have changed in the MapElem call
+		if err := walk(v.MapIndex(k), w); err != nil {
 			return err
 		}
 
diff --git a/reflectwalk_test.go b/reflectwalk_test.go
index 678ebcf..8936a9a 100644
--- a/reflectwalk_test.go
+++ b/reflectwalk_test.go
@@ -98,6 +98,19 @@ func (t *TestMapWalker) MapElem(m, k, v reflect.Value) error {
 	return nil
 }
 
+type TestMapElemReplaceWalker struct {
+	ValueFn func(v reflect.Value) reflect.Value
+}
+
+func (t *TestMapElemReplaceWalker) Map(m reflect.Value) error {
+	return nil
+}
+
+func (t *TestMapElemReplaceWalker) MapElem(m, k, v reflect.Value) error {
+	m.SetMapIndex(k, t.ValueFn(v))
+	return nil
+}
+
 type TestSliceWalker struct {
 	Count    int
 	SliceVal reflect.Value
@@ -355,6 +368,61 @@ func TestWalk_Map(t *testing.T) {
 	}
 }
 
+func TestWalk_Map_ReplaceValue(t *testing.T) {
+	w := &TestMapElemReplaceWalker{
+		ValueFn: func(v reflect.Value) reflect.Value {
+			if v.Type().Kind() == reflect.String {
+				return reflect.ValueOf("replaced")
+			}
+
+			if v.Type().Kind() == reflect.Interface {
+				if elem := v.Elem(); elem.Type() == reflect.TypeOf(map[string]interface{}{}) {
+					newMap := make(map[string]interface{})
+					for _, k := range elem.MapKeys() {
+						newMap[k.String()] = elem.MapIndex(k).Interface()
+					}
+					newMap["extra-replaced"] = "not-replaced"
+					return reflect.ValueOf(newMap)
+				} else if elem.Type().Kind() == reflect.String {
+					return reflect.ValueOf("replaced")
+				}
+			}
+
+			return v
+		},
+	}
+
+	type S struct {
+		Foo map[string]interface{}
+	}
+
+	data := &S{
+		Foo: map[string]interface{}{
+			"foo": map[string]interface{}{
+				"bar": map[string]string{"baz": "should-get-replaced"},
+			},
+		},
+	}
+
+	expected := &S{
+		Foo: map[string]interface{}{
+			"foo": map[string]interface{}{
+				"bar":            map[string]string{"baz": "replaced"},
+				"extra-replaced": "replaced",
+			},
+		},
+	}
+
+	err := Walk(data, w)
+	if err != nil {
+		t.Fatalf("err: %v", err)
+	}
+
+	if !reflect.DeepEqual(data, expected) {
+		t.Fatalf("Values not equal: %#v", data)
+	}
+}
+
 func TestWalk_Pointer(t *testing.T) {
 	w := new(TestPointerWalker)
 

Full worker log Full build log