File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,12 @@ int main(int argc, char* argv[]) {
317
317
if (further_args_are_strings ) {
318
318
ARGS = jv_array_append (ARGS , jv_string (argv [i ]));
319
319
} else if (further_args_are_json ) {
320
- ARGS = jv_array_append (ARGS , jv_parse (argv [i ]));
320
+ jv v = jv_parse (argv [i ]);
321
+ if (!jv_is_valid (v )) {
322
+ fprintf (stderr , "%s: invalid JSON text passed to --jsonargs\n" , progname );
323
+ die ();
324
+ }
325
+ ARGS = jv_array_append (ARGS , v );
321
326
} else {
322
327
jq_util_input_add_input (input_state , argv [i ]);
323
328
nfiles ++ ;
@@ -330,7 +335,12 @@ int main(int argc, char* argv[]) {
330
335
if (further_args_are_strings ) {
331
336
ARGS = jv_array_append (ARGS , jv_string (argv [i ]));
332
337
} else if (further_args_are_json ) {
333
- ARGS = jv_array_append (ARGS , jv_parse (argv [i ]));
338
+ jv v = jv_parse (argv [i ]);
339
+ if (!jv_is_valid (v )) {
340
+ fprintf (stderr , "%s: invalid JSON text passed to --jsonargs\n" , progname );
341
+ die ();
342
+ }
343
+ ARGS = jv_array_append (ARGS , v );
334
344
} else {
335
345
jq_util_input_add_input (input_state , argv [i ]);
336
346
nfiles ++ ;
Original file line number Diff line number Diff line change 207
207
echo ' {"a":1,"b",' | $JQ --stream > /dev/null 2> $d /err
208
208
grep ' Objects must consist of key:value pairs' $d /err > /dev/null
209
209
210
+ # # Regression test for issue #2572 assert when using --jsonargs and invalid JSON
211
+ $JQ -n --jsonargs null invalid && EC=$? || EC=$?
212
+ if [ " $EC " -ne 2 ]; then
213
+ echo " --jsonargs exited with wrong exit code, expected 2 got $EC " 1>&2
214
+ exit 1
215
+ fi
216
+ # this tests the args_done code path "--"
217
+ $JQ -n --jsonargs null -- invalid && EC=$? || EC=$?
218
+ if [ " $EC " -ne 2 ]; then
219
+ echo " --jsonargs exited with wrong exit code, expected 2 got $EC " 1>&2
220
+ exit 1
221
+ fi
222
+
210
223
# # Fuzz parser
211
224
212
225
# # XXX With a $(urandom) builtin we could move this test into tests/all.test
You can’t perform that action at this time.
0 commit comments