From 12d0d12fa15f7d28bb179ad77775a0d54cb1a6f6 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Fri, 21 Feb 2025 09:40:32 -0300 Subject: [PATCH] fix(mapstr): cast inner maps to M on Clone --- mapstr/mapstr.go | 6 +++--- mapstr/mapstr_test.go | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mapstr/mapstr.go b/mapstr/mapstr.go index 7dc7973b..9e236162 100644 --- a/mapstr/mapstr.go +++ b/mapstr/mapstr.go @@ -169,7 +169,7 @@ func cloneMap(dst, src M) { dst[k] = d cloneMap(d, v) case map[string]interface{}: - d := make(map[string]interface{}, len(v)) + d := make(M, len(v)) dst[k] = d cloneMap(d, v) case []M: @@ -181,9 +181,9 @@ func cloneMap(dst, src M) { } dst[k] = a case []map[string]interface{}: - a := make([]map[string]interface{}, 0, len(v)) + a := make([]M, 0, len(v)) for _, m := range v { - d := make(map[string]interface{}, len(m)) + d := make(M, len(m)) cloneMap(d, m) a = append(a, d) } diff --git a/mapstr/mapstr_test.go b/mapstr/mapstr_test.go index 3bbdf8c4..90a71376 100644 --- a/mapstr/mapstr_test.go +++ b/mapstr/mapstr_test.go @@ -349,6 +349,8 @@ func TestClone(t *testing.T) { "c32": 2, }, "c4": []M{{"c41": 1}}, + "c5": map[string]interface{}{"c51": 1}, + "c6": []map[string]interface{}{{"c61": 1}}, } // Clone the original mapstr and then increment every value in it. Ensures the test will fail if @@ -366,6 +368,8 @@ func TestClone(t *testing.T) { "c32": 2, }, "c4": []M{{"c41": 1}}, + "c5": M{"c51": 1}, + "c6": []M{{"c61": 1}}, }, cloned, )