Skip to content

Commit

Permalink
fix iterator traversal empty object panic (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxsong committed Oct 18, 2022
1 parent b52e528 commit 3e6f839
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ast/iterator.go
Expand Up @@ -63,7 +63,11 @@ func (self *Iterator) HasNext() bool {
} else if self.p.t == _V_ARRAY_LAZY {
return self.p.skipNextNode().Valid()
} else if self.p.t == _V_OBJECT_LAZY {
return self.p.skipNextPair().Value.Valid()
pair := self.p.skipNextPair()
if pair == nil {
return false
}
return pair.Value.Valid()
}
return false
}
Expand Down
10 changes: 10 additions & 0 deletions ast/iterator_test.go
Expand Up @@ -195,6 +195,16 @@ func TestIterator(t *testing.T) {
if i != int64(loop) {
t.Fatal(i)
}

str, _ = getTestIteratorSample(0)
root, err = NewParser(str).Parse()
if err != 0 {
t.Fatal(err)
}
mi, _ = root.Get("object").Properties()
if mi.HasNext() {
t.Fatalf("should not have next")
}
}

func BenchmarkArrays(b *testing.B) {
Expand Down

0 comments on commit 3e6f839

Please sign in to comment.