Explorar o código

fix #190 handle empty input

Tao Wen %!s(int64=8) %!d(string=hai) anos
pai
achega
aed5a81f09
Modificáronse 2 ficheiros con 8 adicións e 0 borrados
  1. 3 0
      feature_any.go
  2. 5 0
      jsoniter_skip_test.go

+ 3 - 0
feature_any.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"io"
 	"reflect"
+	"errors"
 )
 
 // Any generic object representation.
@@ -157,6 +158,8 @@ func (iter *Iterator) readAny() Any {
 		return iter.readArrayAny()
 	case '-':
 		return iter.readNumberAny(false)
+	case 0:
+		return &invalidAny{baseAny{}, errors.New("input is empty")}
 	default:
 		return iter.readNumberAny(true)
 	}

+ 5 - 0
jsoniter_skip_test.go

@@ -104,6 +104,11 @@ func Test_skip_and_return_bytes_with_reader(t *testing.T) {
 	should.Equal(`{"a" : [{"stream": "c"}], "d": 102 }`, string(skipped))
 }
 
+func Test_skip_empty(t *testing.T) {
+	should := require.New(t)
+	should.NotNil(Get([]byte("")).LastError())
+}
+
 type TestResp struct {
 	Code uint64
 }