mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
fix #190 handle empty input
This commit is contained in:
parent
f1258b01aa
commit
aed5a81f09
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Any generic object representation.
|
// Any generic object representation.
|
||||||
@ -157,6 +158,8 @@ func (iter *Iterator) readAny() Any {
|
|||||||
return iter.readArrayAny()
|
return iter.readArrayAny()
|
||||||
case '-':
|
case '-':
|
||||||
return iter.readNumberAny(false)
|
return iter.readNumberAny(false)
|
||||||
|
case 0:
|
||||||
|
return &invalidAny{baseAny{}, errors.New("input is empty")}
|
||||||
default:
|
default:
|
||||||
return iter.readNumberAny(true)
|
return iter.readNumberAny(true)
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,11 @@ func Test_skip_and_return_bytes_with_reader(t *testing.T) {
|
|||||||
should.Equal(`{"a" : [{"stream": "c"}], "d": 102 }`, string(skipped))
|
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 {
|
type TestResp struct {
|
||||||
Code uint64
|
Code uint64
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user