From 0260c89b543da1e80ad3915d33fc79d1875aa101 Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Mon, 6 Aug 2018 13:23:06 +0800 Subject: [PATCH] fix #286 calcHash should use byte not rune to calc hash --- iter_object.go | 13 ++++++------- type_tests/struct_tags_test.go | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/iter_object.go b/iter_object.go index 6e7c370..1c57576 100644 --- a/iter_object.go +++ b/iter_object.go @@ -2,7 +2,7 @@ package jsoniter import ( "fmt" - "unicode" + "strings" ) // ReadObject read one field from object. @@ -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) diff --git a/type_tests/struct_tags_test.go b/type_tests/struct_tags_test.go index 6b111fa..66834b8 100644 --- a/type_tests/struct_tags_test.go +++ b/type_tests/struct_tags_test.go @@ -145,6 +145,9 @@ func init() { (*struct { Field bool `json:",omitempty,string"` })(nil), + (*struct { + Field bool `json:"中文"` + })(nil), ) }