Skip to content

Commit

Permalink
fix(util/gconv): #3731 map type name mismatch in switch case statement (
Browse files Browse the repository at this point in the history
  • Loading branch information
wlynxg authored Sep 9, 2024
1 parent 467a5c1 commit 448df14
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions util/gconv/gconv_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ func doConvert(in doConvertInput) (convertedValue interface{}) {
case "map[string]string":
return MapStrStr(in.FromValue)

case "map[string]interface{}":
case "map[string]interface {}":
return Map(in.FromValue)

case "[]map[string]interface{}":
case "[]map[string]interface {}":
return Maps(in.FromValue)

case "RawMessage", "json.RawMessage":
Expand Down
21 changes: 21 additions & 0 deletions util/gconv/gconv_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package gconv_test

import (
"fmt"
"math/big"
"testing"
"time"
Expand Down Expand Up @@ -366,3 +367,23 @@ func TestIssue3006(t *testing.T) {
t.Assert(ff.Val3["val3"], []byte(`{"hello":"world"}`))
})
}

// https://github.com/gogf/gf/issues/3731
func TestIssue3731(t *testing.T) {
type Data struct {
Doc map[string]interface{} `json:"doc"`
}

gtest.C(t, func(t *gtest.T) {
dataMap := map[string]any{
"doc": map[string]any{
"craft": nil,
},
}

var args Data
err := gconv.Struct(dataMap, &args)
t.AssertNil(err)
t.AssertEQ("<nil>", fmt.Sprintf("%T", args.Doc["craft"]))
})
}

0 comments on commit 448df14

Please sign in to comment.