]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix JSON emission for implicit arrays in libucl
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 16 Feb 2026 19:08:55 +0000 (19:08 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 16 Feb 2026 19:08:55 +0000 (19:08 +0000)
When emitting UCL objects with implicit arrays (multiple values for the
same key) as JSON, the emitter was producing invalid output by:
- Not printing the key before the array for non-first elements
- Missing comma separators between elements

This caused rspamadm configdump -j to output malformed JSON like:
  "actions": {...}[
instead of:
  "actions": {...},
  "group": [

contrib/libucl/ucl_emitter.c

index 2c179694d5b88e129b774c229a4c451a75983260..fb90adcb8b1b24cbc99366f7135acd15ec7cdad5 100644 (file)
@@ -323,10 +323,16 @@ ucl_emitter_common_start_object(struct ucl_emitter_context *ctx,
                else {
                        /* Expand implicit arrays */
                        if (cur->next != NULL) {
-                               if (first) {
-                                       ucl_add_tabs(func, ctx->indent, compact);
+                               if (!first) {
+                                       if (compact) {
+                                               func->ucl_emitter_append_character(',', 1, func->ud);
+                                       }
+                                       else {
+                                               func->ucl_emitter_append_len(",\n", 2, func->ud);
+                                       }
                                }
-                               ucl_emitter_common_start_array(ctx, cur, first, compact);
+                               ucl_add_tabs(func, ctx->indent, compact);
+                               ucl_emitter_common_start_array(ctx, cur, true, compact);
                                ucl_emitter_common_end_array(ctx, cur, compact);
                        }
                        else {