Skip to content

Commit

Permalink
fix json-iterator#286 calcHash should use byte not rune to calc hash
Browse files Browse the repository at this point in the history
  • Loading branch information
taowen committed Aug 6, 2018
1 parent b0bc206 commit 286d521
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 6 additions & 7 deletions iter_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jsoniter

import (
"fmt"
"unicode"
"strings"
)

// ReadObject read one field from object.
Expand Down Expand Up @@ -96,13 +96,12 @@ func (iter *Iterator) readFieldHash() int64 {
}

func calcHash(str string, caseSensitive bool) int64 {
if !caseSensitive {
str = strings.ToLower(str)
}
hash := int64(0x811c9dc5)
for _, b := range str {
if caseSensitive {
hash ^= int64(b)
} else {
hash ^= int64(unicode.ToLower(b))
}
for _, b := range []byte(str) {
hash ^= int64(b)
hash *= 0x1000193
}
return int64(hash)
Expand Down
3 changes: 3 additions & 0 deletions type_tests/struct_tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func init() {
(*struct {
Field bool `json:",omitempty,string"`
})(nil),
(*struct {
Field bool `json:"中文"`
})(nil),
)
}

Expand Down

0 comments on commit 286d521

Please sign in to comment.