From b4a3ab8203b4b41c7cfa017fbb48e7ffda737a52 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 23 Dec 2020 01:28:56 +0900 Subject: [PATCH] Fix rule of lower key --- decode_compile.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/decode_compile.go b/decode_compile.go index c75b8a9..488c8bb 100644 --- a/decode_compile.go +++ b/decode_compile.go @@ -236,7 +236,10 @@ func (d *Decoder) removeConflictFields(fieldMap map[string]*structFieldSet, conf isTaggedKey: v.isTaggedKey, } fieldMap[k] = fieldSet - fieldMap[strings.ToLower(k)] = fieldSet + lower := strings.ToLower(k) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } continue } if set.isTaggedKey { @@ -254,7 +257,10 @@ func (d *Decoder) removeConflictFields(fieldMap map[string]*structFieldSet, conf isTaggedKey: v.isTaggedKey, } fieldMap[k] = fieldSet - fieldMap[strings.ToLower(k)] = fieldSet + lower := strings.ToLower(k) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } } else { // conflict tag key delete(fieldMap, k) @@ -313,7 +319,10 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod isTaggedKey: v.isTaggedKey, } fieldMap[k] = fieldSet - fieldMap[strings.ToLower(k)] = fieldSet + lower := strings.ToLower(k) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } continue } if set.isTaggedKey { @@ -331,7 +340,10 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod isTaggedKey: v.isTaggedKey, } fieldMap[k] = fieldSet - fieldMap[strings.ToLower(k)] = fieldSet + lower := strings.ToLower(k) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } } else { // conflict tag key delete(fieldMap, k) @@ -349,10 +361,16 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod fieldSet := &structFieldSet{dec: dec, offset: field.Offset, isTaggedKey: tag.isTaggedKey} if tag.key != "" { fieldMap[tag.key] = fieldSet - fieldMap[strings.ToLower(tag.key)] = fieldSet + lower := strings.ToLower(tag.key) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } } else { fieldMap[field.Name] = fieldSet - fieldMap[strings.ToLower(field.Name)] = fieldSet + lower := strings.ToLower(field.Name) + if _, exists := fieldMap[lower]; !exists { + fieldMap[lower] = fieldSet + } } } }