Skip to content

Commit

Permalink
fix: dont dump detailled map of the target if the target is a map
Browse files Browse the repository at this point in the history
Signed-off-by: francois  samin <[email protected]>
  • Loading branch information
fsamin committed May 2, 2022
1 parent db680ab commit 1fe65a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,22 @@ func Test_DumpTime(t *testing.T) {

}

func Test_DumpMap(t *testing.T) {
m := map[string]interface{}{
"string": "foobar",
}
e := dump.NewDefaultEncoder()
e.ExtraFields.Len = true
e.ExtraFields.Type = true
e.ExtraFields.DetailedStruct = true
e.ExtraFields.DetailedMap = true
e.ExtraFields.DetailedArray = true
result, err := e.ToStringMap(m)
require.NoError(t, err)
t.Log(result)
require.Len(t, result, 3)
}

func Test_DumpTimeWithDetailledStruct(t *testing.T) {
m := map[string]interface{}{
"string": "foobar",
Expand Down
6 changes: 4 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ func (e *Encoder) fDumpMap(w map[string]interface{}, i interface{}, roots []stri
w[nodeLenFormatted] = lenKeys
}
if e.ExtraFields.DetailedMap {
structKey := strings.Join(sliceFormat(roots, e.Formatters), e.Separator)
w[structKey] = i
if len(roots) != 0 {
structKey := strings.Join(sliceFormat(roots, e.Formatters), e.Separator)
w[structKey] = i
}
}
return nil
}
Expand Down

0 comments on commit 1fe65a0

Please sign in to comment.