Skip to content

Commit b202a03

Browse files
authored
#7: panic with empty data or string (#19)
1 parent 25ea868 commit b202a03

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (s *Stream) GoTo(id int) *Stream {
166166
// IsValid checks if stream is valid.
167167
// This means that the pointer has not reached the end of the stream.
168168
func (s *Stream) IsValid() bool {
169-
return s.current != undefToken
169+
return s.current != nil && s.current != undefToken
170170
}
171171

172172
// IsNextSequence checks if these are next tokens in exactly the same sequence as specified.

stream_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ func TestIssue9(t *testing.T) {
272272
}
273273
}
274274

275+
func TestIssue7(t *testing.T) {
276+
p := New()
277+
buf := bytes.NewBuffer(nil)
278+
279+
stream := p.ParseStream(buf, 4096)
280+
defer stream.Close()
281+
282+
for stream.IsValid() {
283+
token := stream.CurrentToken()
284+
require.False(t, token.Is(TokenInteger))
285+
stream.GoNext()
286+
}
287+
}
288+
275289
var pattern = []byte(`<item count=10 valid id="n9762"> Носки <![CDATA[ socks ]]></item>`)
276290

277291
type dataGenerator struct {

0 commit comments

Comments
 (0)