summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2015-04-20 16:51:48 -0400
committerAssaf Gordon <assafgordon@gmail.com>2015-04-20 16:51:48 -0400
commit2dc8621d05f616f0e656ad6debfede2c3567bbb8 (patch)
treea80c272aa7870d6fbd549714b841e9df243e6f55 /builtin.c
parentb6cc00fa7199772dc88dfe086c9289e5524e1742 (diff)
Handle NUL in escaped-string output
When escaping string (e.g. for `@tsv` or `@csv` outputs), escape NULs as '\0'. Existing behaviour, unchanged by this patch: $ echo '"a\u0000b"' | ./jq '.' "a\u0000b" $ echo '"a\u0000b"' | ./jq -r '.' | od -a 0000000 a nul b nl 0000004 When using `@tsv`, escape NUL to `\0`: $ echo '"a\u0000b"' | ./jq -r '[.]|@tsv' a\0b $ echo '"a\u0000b"' | ./jq '[.]|@tsv' "a\\0b"
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin.c b/builtin.c
index 16037983..24838ea6 100644
--- a/builtin.c
+++ b/builtin.c
@@ -336,6 +336,7 @@ static jv escape_string(jv input, const char* escapings) {
assert(jv_get_kind(input) == JV_KIND_STRING);
const char* lookup[128] = {0};
const char* p = escapings;
+ lookup[0] = "\\0";
while (*p) {
lookup[(int)*p] = p+1;
p++;
@@ -349,7 +350,6 @@ static jv escape_string(jv input, const char* escapings) {
const char* cstart;
int c = 0;
while ((i = jvp_utf8_next((cstart = i), end, &c))) {
- assert(c > 0);
if (c < 128 && lookup[c]) {
ret = jv_string_append_str(ret, lookup[c]);
} else {