Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (decoder) return io.EOF when read nothing from io.Reader #254

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
jobs:
analyze:
name: Analyze
runs-on: self-hosted
runs-on: [self-hosted, X64]
permissions:
actions: read
contents: read
Expand Down
3 changes: 3 additions & 0 deletions decoder/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ read_more:
if err != nil {
repeat = false
if err == io.EOF {
if len(buf) == 0 {
return err
}
break
}
self.err = err
Expand Down
14 changes: 14 additions & 0 deletions decoder/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ var (
strings.Repeat("2",1024)+`"} b {}`
)

func TestDecodeEmpty(t *testing.T) {
var str = ``
var r1 = strings.NewReader(str)
var v1 interface{}
var d1 = json.NewDecoder(r1)
var r2 = strings.NewReader(str)
var v2 interface{}
var d2 = NewStreamDecoder(r2)
es1 := d1.Decode(&v1)
ee1 := d2.Decode(&v2)
assert.Equal(t, es1, ee1)
assert.Equal(t, v1, v2)
}

func TestDecodeSingle(t *testing.T) {
var str = _Single_JSON

Expand Down