]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: only recognize closed object as final element
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Dec 2023 17:42:44 +0000 (18:42 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 12 Dec 2023 18:41:16 +0000 (19:41 +0100)
When streaming JSON normal values also have indent == 1.
For those however it is incorrect to close the stream.

Fixes #2644
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
lib/jsonwrt.c

index dc20d2e46e4593019a5c547937fd77dfbcb9e5f2..243ed82326d9cf7c2a48e04b36aab92f170d1241 100644 (file)
@@ -154,12 +154,6 @@ void ul_jsonwrt_open(struct ul_jsonwrt *fmt, const char *name, int type)
 
 void ul_jsonwrt_close(struct ul_jsonwrt *fmt, int type)
 {
-       if (fmt->indent == 1) {
-               fputs("\n}\n", fmt->out);
-               fmt->indent--;
-               fmt->after_close = 1;
-               return;
-       }
        assert(fmt->indent > 0);
 
        switch (type) {
@@ -168,6 +162,8 @@ void ul_jsonwrt_close(struct ul_jsonwrt *fmt, int type)
                fputc('\n', fmt->out);
                ul_jsonwrt_indent(fmt);
                fputs("}", fmt->out);
+               if (fmt->indent == 0)
+                       fputs("\n", fmt->out);
                break;
        case UL_JSON_ARRAY:
                fmt->indent--;