Skip to content

Commit 8b03463

Browse files
authored
fix(mapstr): cast inner maps to M on Clone (#283)
1 parent 0ab6544 commit 8b03463

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

mapstr/mapstr.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func cloneMap(dst, src M) {
169169
dst[k] = d
170170
cloneMap(d, v)
171171
case map[string]interface{}:
172-
d := make(map[string]interface{}, len(v))
172+
d := make(M, len(v))
173173
dst[k] = d
174174
cloneMap(d, v)
175175
case []M:
@@ -181,9 +181,9 @@ func cloneMap(dst, src M) {
181181
}
182182
dst[k] = a
183183
case []map[string]interface{}:
184-
a := make([]map[string]interface{}, 0, len(v))
184+
a := make([]M, 0, len(v))
185185
for _, m := range v {
186-
d := make(map[string]interface{}, len(m))
186+
d := make(M, len(m))
187187
cloneMap(d, m)
188188
a = append(a, d)
189189
}

mapstr/mapstr_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ func TestClone(t *testing.T) {
349349
"c32": 2,
350350
},
351351
"c4": []M{{"c41": 1}},
352+
"c5": map[string]interface{}{"c51": 1},
353+
"c6": []map[string]interface{}{{"c61": 1}},
352354
}
353355

354356
// 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) {
366368
"c32": 2,
367369
},
368370
"c4": []M{{"c41": 1}},
371+
"c5": M{"c51": 1},
372+
"c6": []M{{"c61": 1}},
369373
},
370374
cloned,
371375
)

0 commit comments

Comments
 (0)