Skip to content

Commit

Permalink
fix:(decoder) more loose repeatable condition for StreamDecoder (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Sep 8, 2022
1 parent 6e979df commit a48cad8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion decoder/stream.go
Expand Up @@ -127,7 +127,7 @@ read_more:

func (self StreamDecoder) repeatable(err error) bool {
if ee, ok := err.(SyntaxError); ok &&
(ee.Code == types.ERR_EOF || (ee.Code == types.ERR_INVALID_CHAR && self.i == len(self.s)-1)) {
(ee.Code == types.ERR_EOF || (ee.Code == types.ERR_INVALID_CHAR && self.i >= len(self.s)-1)) {
return true
}
return false
Expand Down
16 changes: 16 additions & 0 deletions issue_test/issue293_test.go
Expand Up @@ -35,4 +35,20 @@ func TestIssue293(t *testing.T) {
if err != nil {
t.Fatal(err)
}
}

func TestIssue293Sign(t *testing.T) {
left := `{"a":`
var data = left+strings.Repeat(" ", 4096 - len(left)-1) + "-33.0}"
sd := decoder.NewStreamDecoder(strings.NewReader(data))
var v = struct{
A json.RawMessage
}{}
err := sd.Decode(&v)
if err != nil {
if e, ok := err.(decoder.SyntaxError); ok {
t.Fatal(e.Description())
}
t.Fatal(err)
}
}

0 comments on commit a48cad8

Please sign in to comment.