fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732)

This commit is contained in:
gopherfarm 2024-09-09 14:54:40 +08:00 committed by GitHub
parent 467a5c1093
commit 448df14860
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -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":

View File

@ -7,6 +7,7 @@
package gconv_test
import (
"fmt"
"math/big"
"testing"
"time"
@ -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"]))
})
}