Skip to content

Commit d666284

Browse files
n-peugnetbzick
authored andcommitted
Fix panic when stream ends with any white space
Fixes: #26
1 parent 6439370 commit d666284

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (p *parsing) checkPoint() bool {
150150

151151
// parse bytes (p.str) to tokens and append them to the end if stream of tokens.
152152
func (p *parsing) parse() {
153-
if len(p.str) == 0 {
153+
if len(p.str) == p.pos {
154154
if p.reader == nil || p.loadChunk() == 0 { // if it's not an infinite stream, or this is the end of the stream
155155
return
156156
}

stream_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,19 @@ func TestIssue9(t *testing.T) {
273273
}
274274
}
275275

276+
// TestIssue26 panic when stream with more than one token ends with any white space
277+
func TestIssue26(t *testing.T) {
278+
parser := New()
279+
buf := bytes.NewBufferString("test coucou\n")
280+
281+
stream := parser.ParseStream(buf, 4096)
282+
defer stream.Close()
283+
for stream.IsValid() {
284+
// do something...
285+
stream.GoNext() // Should not panic
286+
}
287+
}
288+
276289
func TestStreamOverflow(t *testing.T) {
277290
parser := New()
278291
buf := bytes.NewBuffer([]byte("a b c"))

0 commit comments

Comments
 (0)