]> 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>
Wed, 13 Dec 2023 18:29:33 +0000 (19:29 +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>
(cherry picked from commit 5130ce8ee5b71c249e0c8bb7a4975dc8a48c64fa)

lib/jsonwrt.c

index 8ca1d4d9a3b2e687940c448d35d8b0c0d042d15a..9ba6d1f534517744a476dabd41d212374a3ea01b 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--;