jq
jq copied to clipboard
Crash after assertion failure with default and string padding
Describe the bug Assertion failure followed by crash:
assertion "cb == jq_util_input_next_input_cb" failed: file "/usr/src/ports/jq/jq-1.6-1.x86_64/src/jq-1.6/src/util.c", line 371, function: jq_util_input_get_position
*** starting debugger for pid 41552, tid 6648
To Reproduce
$ curl https://www.floatrates.com/daily/USD.json|jq -cr '[ "FloatR", .cad.date, (.cad.rate//1)|tostring|(.+(" "*15))[:15], (.eur.rate//1)|tostring|(.+(" "*15))[:15], (.gbp.rate//1)|tostring|(.+(" "*15))[:15], (.usd.rate//1)|tostring|(.+(" "*15))[:15] ] | @tsv'
Expected behavior Same results with multiple values as with one:
$ curl https://www.floatrates.com/daily/USD.json|jq -cr '["FloatR",.usd.date,(.usd.rate//1)|tostring|(.+(" "*15))[:15]] | @tsv' | cat -A
FloatR ^Inull ^I1 $
Environment (please complete the following information):
$ jq -V
jq-1.6
$ uname -srvmo
CYGWIN_NT-10.0-19044 3.3.5-341.x86_64 2022-05-13 12:27 UTC x86_64 Cygwin
$ win-ver.sh
Windows 10 Home Client Core Multiprocessor Free 6.3 21H2 2009 vb_release 10 0 19044 1766
installed 2021 Apr 13 Tue 12:03:45
Additional context
$ fgrep -nB6 -A14 'cb == jq_util_input_next_input_cb' /usr/src/debug/jq-1.6-1/src/util.c
365-
366-// Return the current_filename:current_line
367-jv jq_util_input_get_position(jq_state *jq) {
368- jq_input_cb cb = NULL;
369- void *cb_data = NULL;
370- jq_get_input_cb(jq, &cb, &cb_data);
371: assert(cb == jq_util_input_next_input_cb);
372- if (cb != jq_util_input_next_input_cb)
373- return jv_invalid_with_msg(jv_string("Invalid jq_util_input API usage"));
374- jq_util_input_state *s = (jq_util_input_state *)cb_data;
375-
376- // We can't assert that current_filename is a string because if
377- // the error was a JSON parser error then we may not have set
378- // current_filename yet.
379- if (jv_get_kind(s->current_filename) != JV_KIND_STRING)
380- return jv_string("<unknown>");
381-
382- jv v = jv_string_fmt("%s:%lu", jv_string_value(s->current_filename), (unsigned long)s->current_line);
383- return v;
384-}
385-
I'm not sure about the assertion failure, but your query is missing some parentheses. Since ',' has higher associativity than |
in jq, you need parentheses around each array elements.
$ jq -n '[1, 2|3, 4|5]'
[
5,
5,
5,
5
]
$ jq -n '[1, (2|3), 4|5]'
[
5,
5,
5
]
$ jq -n '[1, (2|3), (4|5)]'
[
1,
3,
5
]
Thanks - that works. Looked but didn't find any obvious docs on operator precedence/priority. Is there a grammar summary, diagram, something in a source file, or out there? I found a short list in parser.y
: that will do me for now.
See the (semi-official) language description: https://github.com/stedolan/jq/wiki/jq-Language-Description and especially the table at https://github.com/stedolan/jq/wiki/jq-Language-Description#operators-priority
Maybe these could be interesting also: https://github.com/fadado/JBOL/blob/master/doc/JQ-language-grammar.md https://github.com/fadado/JBOL/blob/master/doc/JQ-Distilled.md
Thanks folks, these look interesting and useful, I was unaware the Wiki was populated, so I will also read Advanced Topics and other linked articles, to increase my knowledge above the level of casual user. ;^>