Skip to content

Commit 24bb2ee

Browse files
committed
fix #236 case sensitive when both upper case and lower case presents
1 parent 64cc784 commit 24bb2ee

4 files changed

+184
-185
lines changed

feature_iter_object.go

+40-39
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,63 @@ func (iter *Iterator) ReadObject() (ret string) {
4545
}
4646
}
4747

48-
func (iter *Iterator) readFieldHash() int32 {
48+
// CaseInsensitive
49+
func (iter *Iterator) readFieldHash() int64 {
4950
hash := int64(0x811c9dc5)
5051
c := iter.nextToken()
51-
if c == '"' {
52-
for {
53-
for i := iter.head; i < iter.tail; i++ {
54-
// require ascii string and no escape
55-
b := iter.buf[i]
56-
if !iter.cfg.objectFieldMustBeSimpleString && b == '\\' {
57-
iter.head = i
58-
for _, b := range iter.readStringSlowPath() {
59-
if 'A' <= b && b <= 'Z' {
60-
b += 'a' - 'A'
61-
}
62-
hash ^= int64(b)
63-
hash *= 0x1000193
64-
}
65-
c = iter.nextToken()
66-
if c != ':' {
67-
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
68-
return 0
52+
if c != '"' {
53+
iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c}))
54+
return 0
55+
}
56+
for {
57+
for i := iter.head; i < iter.tail; i++ {
58+
// require ascii string and no escape
59+
b := iter.buf[i]
60+
if b == '\\' {
61+
iter.head = i
62+
for _, b := range iter.readStringSlowPath() {
63+
if 'A' <= b && b <= 'Z' {
64+
b += 'a' - 'A'
6965
}
70-
return int32(hash)
66+
hash ^= int64(b)
67+
hash *= 0x1000193
7168
}
72-
if b == '"' {
73-
iter.head = i + 1
74-
c = iter.nextToken()
75-
if c != ':' {
76-
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
77-
return 0
78-
}
79-
return int32(hash)
69+
c = iter.nextToken()
70+
if c != ':' {
71+
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
72+
return 0
8073
}
81-
if 'A' <= b && b <= 'Z' {
82-
b += 'a' - 'A'
74+
return hash
75+
}
76+
if b == '"' {
77+
iter.head = i + 1
78+
c = iter.nextToken()
79+
if c != ':' {
80+
iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
81+
return 0
8382
}
84-
hash ^= int64(b)
85-
hash *= 0x1000193
83+
return hash
8684
}
87-
if !iter.loadMore() {
88-
iter.ReportError("readFieldHash", `incomplete field name`)
89-
return 0
85+
if 'A' <= b && b <= 'Z' {
86+
b += 'a' - 'A'
9087
}
88+
hash ^= int64(b)
89+
hash *= 0x1000193
90+
}
91+
if !iter.loadMore() {
92+
iter.ReportError("readFieldHash", `incomplete field name`)
93+
return 0
9194
}
9295
}
93-
iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c}))
94-
return 0
9596
}
9697

97-
func calcHash(str string) int32 {
98+
func calcHash(str string) int64 {
9899
hash := int64(0x811c9dc5)
99100
for _, b := range str {
100101
hash ^= int64(unicode.ToLower(b))
101102
hash *= 0x1000193
102103
}
103-
return int32(hash)
104+
return int64(hash)
104105
}
105106

106107
// ReadObjectCB read object with callback, the key is ascii only and field name not copied

feature_reflect_object.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"io"
66
"reflect"
7-
"strings"
87
"unsafe"
98
)
109

@@ -97,7 +96,7 @@ func decoderOfStruct(cfg *frozenConfig, prefix string, typ reflect.Type) ValDeco
9796
}
9897
fields := map[string]*structFieldDecoder{}
9998
for k, binding := range bindings {
100-
fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder)
99+
fields[k] = binding.Decoder.(*structFieldDecoder)
101100
}
102101
return createStructDecoder(cfg, typ, fields)
103102
}

0 commit comments

Comments
 (0)