Skip to content
Myr

Validate JSON for --jsonarg

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #2572

authored by Mattias Wadman · committed by Nico Williams · parent c077b95 · Browse files · 2 files+25 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−2 removed

  • tests:+13 added−0 removed
  • other:+12 added−2 removed

2 files+25 added−2 removed

modified:src/main.c+12 added-2 removed
315 unmodified lines
316 if (args_done) {317 if (further_args_are_strings) {318 ARGS = jv_array_append(ARGS, jv_string(argv[i]));319 } else if (further_args_are_json) {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 }320 ARGS = jv_array_append(ARGS, jv_parse(argv[i]));325 ARGS = jv_array_append(ARGS, v);326 } else {327 jq_util_input_add_input(input_state, argv[i]);328 nfiles++;329 }
4 unmodified lines
334 if (program) {335 if (further_args_are_strings) {336 ARGS = jv_array_append(ARGS, jv_string(argv[i]));337 } else if (further_args_are_json) {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 }333 ARGS = jv_array_append(ARGS, jv_parse(argv[i]));343 ARGS = jv_array_append(ARGS, v);344 } else {345 jq_util_input_add_input(input_state, argv[i]);346 nfiles++;347 }
391 unmodified lines
modified:tests/shtest+13 added
205 unmodified lines
206## Regression test for issue #2378 assert when stream parse broken object pair207echo '{"a":1,"b",' | $JQ --stream > /dev/null 2> $d/err208grep 'Objects must consist of key:value pairs' $d/err > /dev/null209210## Regression test for issue #2572 assert when using --jsonargs and invalid JSON211$JQ -n --jsonargs null invalid && EC=$? || EC=$?212if [ "$EC" -ne 2 ]; then213 echo "--jsonargs exited with wrong exit code, expected 2 got $EC" 1>&2214 exit 1215fi216# this tests the args_done code path "--"217$JQ -n --jsonargs null -- invalid && EC=$? || EC=$?218if [ "$EC" -ne 2 ]; then219 echo "--jsonargs exited with wrong exit code, expected 2 got $EC" 1>&2220 exit 1221fi222223## Fuzz parser224225## XXX With a $(urandom) builtin we could move this test into tests/all.test226clean=false
140 unmodified lines