jaq
jaq copied to clipboard
Stack overflow when recursively assigning something with iterable values
$ 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 | .. = []'
[]
@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.
I addressed this in #285.