Skip to content

Commit f88871b

Browse files
committed
fix #263, support empty string as 0 in fuzz mode
1 parent f246f80 commit f88871b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

extra/fuzzy_decoder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
217217
default:
218218
iter.ReportError("fuzzyIntegerDecoder", "not number or string")
219219
}
220+
if len(str) == 0 {
221+
str = "0"
222+
}
220223
newIter := iter.Pool().BorrowIterator([]byte(str))
221224
defer iter.Pool().ReturnIterator(newIter)
222225
isFloat := strings.IndexByte(str, '.') != -1

extra/fuzzy_decoder_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func Test_any_to_int64(t *testing.T) {
3737
should.Equal(int64(10), val)
3838
should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
3939
should.Equal(int64(10), val)
40+
should.Nil(jsoniter.UnmarshalFromString(`""`, &val))
41+
should.Equal(int64(0), val)
4042

4143
// bool part
4244
should.Nil(jsoniter.UnmarshalFromString(`false`, &val))

0 commit comments

Comments
 (0)