Open cezarguimaraes opened 5 months ago
Describe the bug Attempting to use the filtered value (i.e node.String() or ast.Walk) of a path which combines IndexAll and Child might lead to seg fault if not all sequence elements contain the property being selected by Child
node.String()
ast.Walk
IndexAll
Child
To Reproduce
https://go.dev/play/p/hxD0l_fdVYO
I have added a test case here that reproduces the issue
https://github.com/cezarguimaraes/go-yaml/commit/19b75089e16378395b40a0f17a75c1b406b8334c
Expected behavior
Taking jq as inspiration, partial results should be returned, possibly with nil elements:
jq
nil
$ echo '[{"foo": 1}, {}]' | jq ".[].foo" 1 null
Screenshots
Version Variables
go version go1.22.1 linux/amd64
(tag: v1.11.3)
Additional context I have a tentative fix in this branch https://github.com/goccy/go-yaml/compare/master...cezarguimaraes:go-yaml:fix-indexAll-child-segfault As can be seen by the tests added, the code from this branch simulates jq behavior by returning ast.Null. Another possible approach (preserved by the comments in (*indexAllNode).filter completely filter out unmatched nodes.
ast.Null
(*indexAllNode).filter
Describe the bug Attempting to use the filtered value (i.e
node.String()
orast.Walk
) of a path which combinesIndexAll
andChild
might lead to seg fault if not all sequence elements contain the property being selected byChild
To Reproduce
https://go.dev/play/p/hxD0l_fdVYO
I have added a test case here that reproduces the issue
https://github.com/cezarguimaraes/go-yaml/commit/19b75089e16378395b40a0f17a75c1b406b8334c
Expected behavior
Taking
jq
as inspiration, partial results should be returned, possibly withnil
elements:Screenshots
Version Variables
go version go1.22.1 linux/amd64
(tag: v1.11.3)
and mainAdditional context I have a tentative fix in this branch https://github.com/goccy/go-yaml/compare/master...cezarguimaraes:go-yaml:fix-indexAll-child-segfault As can be seen by the tests added, the code from this branch simulates
jq
behavior by returningast.Null
. Another possible approach (preserved by the comments in(*indexAllNode).filter
completely filter out unmatched nodes.