From: Thomas Weißschuh Date: Tue, 12 Dec 2023 17:42:44 +0000 (+0100) Subject: libsmartcols: only recognize closed object as final element X-Git-Tag: v2.39.4~13^2~1 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=261c9309485818a9c0c04c18da69413149d8f8a8;p=thirdparty%2Futil-linux.git libsmartcols: only recognize closed object as final element 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 (cherry picked from commit 5130ce8ee5b71c249e0c8bb7a4975dc8a48c64fa) --- diff --git a/lib/jsonwrt.c b/lib/jsonwrt.c index 8ca1d4d9a3..9ba6d1f534 100644 --- a/lib/jsonwrt.c +++ b/lib/jsonwrt.c @@ -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--;