Skip to content

Commit

Permalink
Fix halt_error to output the message in raw mode as documented
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Jun 26, 2023
1 parent afdc922 commit f6f2a7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ static int process(jq_state *jq, jv value, int flags, int dumpopts) {
jv error_message = jq_get_error_message(jq);
if (jv_get_kind(error_message) == JV_KIND_STRING) {
// No prefix should be added to the output of `halt_error`.
fprintf(stderr, "%s", jv_string_value(error_message));
fwrite(jv_string_value(error_message), 1,
jv_string_length_bytes(jv_copy(error_message)), stderr);
} else if (jv_get_kind(error_message) == JV_KIND_NULL) {
// Halt with no output
} else if (jv_is_valid(error_message)) {
Expand Down
6 changes: 5 additions & 1 deletion tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n" | halt_error(1)' 2>/dev/null)" ]; then
echo "jq halt_error(1) had unexpected output on stdout" 1>&2
exit 1
fi
if [ "$($VALGRIND $Q $JQ -n '"xyz\n" | halt_error(1)' 2>&1)" != "xyz" ]; then
if [ "$($VALGRIND $Q $JQ -n '"xy" | halt_error(1)' 2>&1 || echo "z")" != "xyz" ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi
if [ "$($VALGRIND $Q $JQ -n '"x\u0000y\u0000z" | halt_error(1)' 2>&1)" != "$(printf 'x\x00y\x00z')" ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi
Expand Down

0 comments on commit f6f2a7b

Please sign in to comment.