diff --git a/decode_test.go b/decode_test.go index a1a10e9c..9306b2e1 100644 --- a/decode_test.go +++ b/decode_test.go @@ -4016,6 +4016,18 @@ func TestIssue408(t *testing.T) { } } +func TestIssue416(t *testing.T) { + b := []byte(`{"Сообщение":"Текст"}`) + + type T struct { + Msg string `json:"Сообщение"` + } + var x T + err := json.Unmarshal(b, &x) + assertErr(t, err) + assertEq(t, "unexpected result", "Текст", x.Msg) +} + func TestIssue429(t *testing.T) { var x struct { N int32 diff --git a/internal/decoder/struct.go b/internal/decoder/struct.go index 4e14a20f..313da153 100644 --- a/internal/decoder/struct.go +++ b/internal/decoder/struct.go @@ -51,6 +51,14 @@ func init() { } } +func toASCIILower(s string) string { + b := []byte(s) + for i := range b { + b[i] = largeToSmallTable[b[i]] + } + return string(b) +} + func newStructDecoder(structName, fieldName string, fieldMap map[string]*structFieldSet) *structDecoder { return &structDecoder{ fieldMap: fieldMap, @@ -91,6 +99,10 @@ func (d *structDecoder) tryOptimize() { for k, v := range d.fieldMap { key := strings.ToLower(k) if key != k { + if key != toASCIILower(k) { + d.isTriedOptimize = true + return + } // already exists same key (e.g. Hello and HELLO has same lower case key if _, exists := conflicted[key]; exists { d.isTriedOptimize = true