mirror of https://github.com/goccy/go-json.git
fix: fixed to not optimize when lower can't handle byte-by-byte. (#432)
This commit is contained in:
parent
b68305f5d1
commit
2ef15e72f8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue