]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix bare array on JSON output
authorKarel Zak <kzak@redhat.com>
Mon, 7 Jun 2021 08:32:20 +0000 (10:32 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Jun 2021 08:32:20 +0000 (10:32 +0200)
The bare array ({[...]}) for top level list of entries is invalid. It
seems better to print empty string than nothing. This is workaround
for broken utils, better is to define a table name.

Addresses: https://github.com/karelzak/util-linux/issues/1339
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/print-api.c

index 50df96416f7d48d1e0996b5f2bf82ed85bbc00d5..237d9ae543bfa6a0d640b4c378f53de28d685141 100644 (file)
@@ -119,7 +119,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty)
                if (scols_table_is_json(tb)) {
                        ul_jsonwrt_init(&tb->json, tb->out, 0);
                        ul_jsonwrt_root_open(&tb->json);
-                       ul_jsonwrt_array_open(&tb->json, tb->name);
+                       ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : "");
                        ul_jsonwrt_array_close(&tb->json);
                        ul_jsonwrt_root_close(&tb->json);
                } else if (is_empty)
@@ -134,7 +134,7 @@ static int do_print_table(struct libscols_table *tb, int *is_empty)
 
        if (scols_table_is_json(tb)) {
                ul_jsonwrt_root_open(&tb->json);
-               ul_jsonwrt_array_open(&tb->json, tb->name);
+               ul_jsonwrt_array_open(&tb->json, tb->name ? tb->name : "");
        }
 
        if (tb->format == SCOLS_FMT_HUMAN)