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

segfault when using the return of a path which combines IndexAll and Child #436

Open
cezarguimaraes opened this issue Mar 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@cezarguimaraes
Copy link

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

To Reproduce

https://go.dev/play/p/hxD0l_fdVYO

I have added a test case here that reproduces the issue

cezarguimaraes@19b7508

Expected behavior

Taking jq as inspiration, partial results should be returned, possibly with nil elements:

$ echo '[{"foo": 1}, {}]' | jq ".[].foo"
1
null

Screenshots
image

Version Variables

  • Go version: go version go1.22.1 linux/amd64
  • go-yaml's Version: (tag: v1.11.3) and main

Additional context
I have a tentative fix in this branch 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.

@cezarguimaraes cezarguimaraes added the bug Something isn't working label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant