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

index using object (without start and end) should always emit an error #2074

Closed
itchyny opened this issue Mar 3, 2020 · 0 comments
Closed

Comments

@itchyny
Copy link
Contributor

itchyny commented Mar 3, 2020

Describe the bug
Indexing with an object should emit an error but does not against null.

To Reproduce

 % echo 'null' | jq '.[{}]'
null
 % echo '{}' | jq '.[{}]'
jq: error (at <stdin>:1): Cannot index object with object
 % echo 'null' | jq '.[[]]'
jq: error (at <stdin>:1): Cannot index object with array
 % echo '{}' | jq '.[[]]'
jq: error (at <stdin>:1): Cannot index object with array

The first case should be an error as well

Expected behavior

 % echo 'null' | jq '.[{}]'
jq: error (at <stdin>:1): Cannot index null with object

Also echo 'null' | jq '.[[]]' should print Cannot index null with array.

Environment (please complete the following information):

  • OS and Version: macOS
  • jq version: jq-master-50a7022

Additional Context
The path function does not emit an error quickly for this case so this function can return an invalid object entry as a path (an element in a path should be either a number, a string or an object with start and end).

 % echo 'null' | jq 'path(.[{"x":42}])'
[
  {
    "x": 42
  }
]
 % echo 'null' | jq '.[{"x":42}] = 1'
jq: error (at <stdin>:1): Start and end indices of an array slice must be numbers

This is a case which shows that null | path(.X) succeeds but null | .X = 1 fails.

@itchyny itchyny changed the title index using object should always emit an error index using object (without start and end) should always emit an error Mar 3, 2020
@itchyny itchyny closed this as completed Nov 21, 2020
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

1 participant