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

Setting non-existent elements of array slices uncovers hidden elements #3022

Open
nicowilliams opened this issue Jan 26, 2024 · 0 comments
Open

Comments

@nicowilliams
Copy link
Contributor

nicowilliams commented Jan 26, 2024

Extending a slice by setting an element that is "hidden" by the slice reveals elements between the last one of the slice and the element being set:

: ; jq -cn '[range(10)][0:3]|(.,(.[5] = true))'
[0,1,2]
[0,1,2,3,4,true]

Appending to a slice works:

: ; jq -cn '[range(10)][0:3]|(.,(.+[true]))'
[0,1,2]
[0,1,2,true]

But then:

: ; jq -cn '[range(10)][1:3]|[.,(.[5] = true)]'
[[1,2],[1,2,null,null,null,true]]

Using offsets other than zero in the slice does not make things worse, fortunately:

: ; jq -cn '[range(10)][1:3]|(.,(.[5] = true))'
[1,2]
[1,2,3,4,5,true]
: ; jq -cn '[range(10)][1:3]|(.,(.+[true]))'
[1,2]
[1,2,true]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants