Browse Source

fix #263, support empty string as 0 in fuzz mode

Tao Wen 7 years ago
parent
commit
f88871b601
2 changed files with 5 additions and 0 deletions
  1. 3 0
      extra/fuzzy_decoder.go
  2. 2 0
      extra/fuzzy_decoder_test.go

+ 3 - 0
extra/fuzzy_decoder.go

@@ -217,6 +217,9 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
 	default:
 		iter.ReportError("fuzzyIntegerDecoder", "not number or string")
 	}
+	if len(str) == 0 {
+		str = "0"
+	}
 	newIter := iter.Pool().BorrowIterator([]byte(str))
 	defer iter.Pool().ReturnIterator(newIter)
 	isFloat := strings.IndexByte(str, '.') != -1

+ 2 - 0
extra/fuzzy_decoder_test.go

@@ -37,6 +37,8 @@ func Test_any_to_int64(t *testing.T) {
 	should.Equal(int64(10), val)
 	should.Nil(jsoniter.UnmarshalFromString(`10`, &val))
 	should.Equal(int64(10), val)
+	should.Nil(jsoniter.UnmarshalFromString(`""`, &val))
+	should.Equal(int64(0), val)
 
 	// bool part
 	should.Nil(jsoniter.UnmarshalFromString(`false`, &val))