Skip to content

Commit aed5a81

Browse files
committed
fix #190 handle empty input
1 parent f1258b0 commit aed5a81

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

feature_any.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"reflect"
7+
"errors"
78
)
89

910
// Any generic object representation.
@@ -157,6 +158,8 @@ func (iter *Iterator) readAny() Any {
157158
return iter.readArrayAny()
158159
case '-':
159160
return iter.readNumberAny(false)
161+
case 0:
162+
return &invalidAny{baseAny{}, errors.New("input is empty")}
160163
default:
161164
return iter.readNumberAny(true)
162165
}

jsoniter_skip_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func Test_skip_and_return_bytes_with_reader(t *testing.T) {
104104
should.Equal(`{"a" : [{"stream": "c"}], "d": 102 }`, string(skipped))
105105
}
106106

107+
func Test_skip_empty(t *testing.T) {
108+
should := require.New(t)
109+
should.NotNil(Get([]byte("")).LastError())
110+
}
111+
107112
type TestResp struct {
108113
Code uint64
109114
}

0 commit comments

Comments
 (0)