Skip to content

Commit

Permalink
#7: panic with empty data or string (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzick authored Apr 5, 2024
1 parent 25ea868 commit b202a03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (s *Stream) GoTo(id int) *Stream {
// IsValid checks if stream is valid.
// This means that the pointer has not reached the end of the stream.
func (s *Stream) IsValid() bool {
return s.current != undefToken
return s.current != nil && s.current != undefToken
}

// IsNextSequence checks if these are next tokens in exactly the same sequence as specified.
Expand Down
14 changes: 14 additions & 0 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ func TestIssue9(t *testing.T) {
}
}

func TestIssue7(t *testing.T) {
p := New()
buf := bytes.NewBuffer(nil)

stream := p.ParseStream(buf, 4096)
defer stream.Close()

for stream.IsValid() {
token := stream.CurrentToken()
require.False(t, token.Is(TokenInteger))
stream.GoNext()
}
}

var pattern = []byte(`<item count=10 valid id="n9762"> Носки <![CDATA[ socks ]]></item>`)

type dataGenerator struct {
Expand Down

0 comments on commit b202a03

Please sign in to comment.