Skip to content

Commit f7bbbfb

Browse files
authored
Merge pull request #10 from davitovmasyan/master
Fixes mergo.Merge skips maps with nil values in it #9
2 parents 439a2df + 6b8e554 commit f7bbbfb

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

flat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func unflatten(flat map[string]interface{}, opts *Options) (nested map[string]in
113113

114114
for k, v := range flat {
115115
temp := uf(k, v, opts).(map[string]interface{})
116-
err = mergo.Merge(&nested, temp)
116+
err = mergo.Merge(&nested, temp, func(c *mergo.Config) {c.Overwrite = true})
117117
if err != nil {
118118
return
119119
}

flat_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ func TestUnflatten(t *testing.T) {
278278
"travis": "true",
279279
},
280280
},
281+
// keys with nil values
282+
{
283+
map[string]interface{}{
284+
"foo.bar": map[string]interface{}{"t": nil},
285+
"foo": map[string]interface{}{"k": nil},
286+
},
287+
nil,
288+
map[string]interface{}{
289+
"foo": map[string]interface{}{
290+
"bar": map[string]interface{}{
291+
"t": nil,
292+
},
293+
"k": nil,
294+
},
295+
},
296+
},
281297
// todo
282298
// overwrite true
283299
// {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/nqd/flat
22

33
go 1.12
44

5-
require github.com/imdario/mergo v0.3.6
5+
require github.com/imdario/mergo v0.3.12

go.sum

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
2-
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
1+
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
2+
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
3+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
4+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
6+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)