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

Stack overflow when recursively assigning something with iterable values #235

Open
wader opened this issue Nov 14, 2024 · 1 comment
Open

Comments

@wader
Copy link
Contributor

wader commented Nov 14, 2024

$ jq -cn '1 | .. = [.]'
[1]

$ cargo run -- -cn '1 | .. = [.]'
thread 'main' has overflowed its stack
fatal runtime error: stack overflow

$ cargo run -- -n '1 | .. = [2]'
thread 'main' has overflowed its stack
fatal runtime error: stack overflow

$ cargo run -- -n '1 | .. = []'
[]
@wader wader mentioned this issue Nov 15, 2024
@01mf02
Copy link
Owner

01mf02 commented Nov 15, 2024

@itchyny has already brought this up in #139.

TL;DR: The update behaviour for .. can yield unexpected results for both jq and jaq (they're just more visible in jaq).
Instead of .. |= f, I recommend defining def recurse_up: (.[]? | recurse_up), .; and using recurse_up |= f instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants