From e93e3659cb94ea58a343633a5a73c2ca614631b1 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 28 Dec 2020 13:19:27 -0800 Subject: [PATCH] fix handling of -0 --- src/main.c | 2 +- tests/shtest | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 4b33f65212..31e9a5ba30 100644 --- a/src/main.c +++ b/src/main.c @@ -105,7 +105,7 @@ static void die() { static int isoptish(const char* text) { - return text[0] == '-' && (text[1] == '-' || isalpha(text[1])); + return text[0] == '-' && (text[1] == '-' || isalpha(text[1]) || text[1] == '0'); } static int isoption(const char* text, char shortopt, const char* longopt, size_t *short_opts) { diff --git a/tests/shtest b/tests/shtest index 8ed62b2213..75f3a85c2e 100755 --- a/tests/shtest +++ b/tests/shtest @@ -150,6 +150,12 @@ cmp $d/out $d/expected printf "[1,2][3,4]\n" | $JQ -cs add > $d/out 2>&1 cmp $d/out $d/expected +# Regression test for -0 / --nul-output +printf "a\0b\0" > $d/expected +printf '["a", "b"]' | $JQ -0 .[] > $d/out 2>&1 +cmp $d/out $d/expected +printf '["a", "b"]' | $JQ --nul-output .[] > $d/out 2>&1 +cmp $d/out $d/expected ## Test streaming parser