summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2023-06-06 07:19:43 -0400
committerGitHub <noreply@github.com>2023-06-06 20:19:43 +0900
commit6c5c8f21151258b8f976015fce5d9c5681aa462b (patch)
treec3f14e5061b951bad89ff88105c2a86f71e9a3a1
parentb8816caf0a7f58c6483f4344e222a6fea47732e8 (diff)
fix handling of -0 (#2235)
-rw-r--r--src/main.c2
-rwxr-xr-xtests/shtest6
2 files changed, 7 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index cabe6ecf..2d202bd6 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 8ed62b22..75f3a85c 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