fix: should not conflict on lower members (#3095)

This commit is contained in:
Kevin Wan 2023-04-08 14:47:57 +08:00 committed by GitHub
parent 92f2676afc
commit 07f03ebd0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -242,6 +242,10 @@ func buildStructFieldsInfo(tp reflect.Type) (*fieldInfo, error) {
for i := 0; i < tp.NumField(); i++ {
field := tp.Field(i)
if !field.IsExported() {
continue
}
name := getTagName(field)
lowerCaseName := toLowerCase(name)
ft := mapping.Deref(field.Type)

View File

@ -1040,6 +1040,24 @@ func TestLoadNamedFieldOverwritten(t *testing.T) {
})
}
func TestLoadLowerMemberShouldNotConflict(t *testing.T) {
type (
Redis struct {
db uint
}
Config struct {
db uint
Redis
}
)
var c Config
assert.NoError(t, LoadFromJsonBytes([]byte(`{}`), &c))
assert.Zero(t, c.db)
assert.Zero(t, c.Redis.db)
}
func TestFillDefaultUnmarshal(t *testing.T) {
t.Run("nil", func(t *testing.T) {
type St struct{}