Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix iterator traversal empty object panic #314

Merged
merged 1 commit into from Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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