Skip to content

Commit 8c7fc75

Browse files
committed
#159 fix fuzzy decoder, the newIter assigned io.EOF error to original iterator, which stopped further processing
1 parent db32ee8 commit 8c7fc75

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

extra/fuzzy_decoder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"reflect"
88
"strings"
99
"unsafe"
10+
"io"
1011
)
1112

1213
const maxUint = ^uint(0)
@@ -206,7 +207,7 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
206207
defer iter.Pool().ReturnIterator(newIter)
207208
isFloat := strings.IndexByte(str, '.') != -1
208209
decoder.fun(isFloat, ptr, newIter)
209-
if newIter.Error != nil {
210+
if newIter.Error != nil && newIter.Error != io.EOF {
210211
iter.Error = newIter.Error
211212
}
212213
}
@@ -225,7 +226,7 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
225226
newIter := iter.Pool().BorrowIterator([]byte(str))
226227
defer iter.Pool().ReturnIterator(newIter)
227228
*((*float32)(ptr)) = newIter.ReadFloat32()
228-
if newIter.Error != nil {
229+
if newIter.Error != nil && newIter.Error != io.EOF {
229230
iter.Error = newIter.Error
230231
}
231232
default:
@@ -247,7 +248,7 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
247248
newIter := iter.Pool().BorrowIterator([]byte(str))
248249
defer iter.Pool().ReturnIterator(newIter)
249250
*((*float64)(ptr)) = newIter.ReadFloat64()
250-
if newIter.Error != nil {
251+
if newIter.Error != nil && newIter.Error != io.EOF {
251252
iter.Error = newIter.Error
252253
}
253254
default:

extra/fuzzy_decoder_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,24 @@ func Test_empty_array_as_object(t *testing.T) {
257257
should.Nil(jsoniter.UnmarshalFromString(`[]`, &val))
258258
should.Equal(struct{}{}, val)
259259
}
260+
261+
func Test_bad_case(t *testing.T) {
262+
var jsonstr = `
263+
{
264+
"extra_type": 181760,
265+
"combo_type": 0,
266+
"trigger_time_ms": 1498800398000,
267+
"_create_time": "2017-06-16 11:21:39",
268+
"_msg_type": 41000
269+
}
270+
`
271+
272+
type OrderEventRequestParams struct {
273+
ExtraType uint64 `json:"extra_type"`
274+
}
275+
276+
var a OrderEventRequestParams
277+
err := jsoniter.UnmarshalFromString(jsonstr, &a)
278+
should := require.New(t)
279+
should.Nil(err)
280+
}

0 commit comments

Comments
 (0)