From beb9293e9b9e867c7cc32d649e33f15528557d4d Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Thu, 16 Feb 2023 14:07:18 -0300 Subject: [PATCH] invalid JSON for non-transaction message in v1 (#266) Non-transactional messages contain only one object. It means comma should not be provided for such JSON objects. If you are sending a non-transactional message into a transaction, it should guarantee that comma is only emitted for transactional commands. Hence, the previous check is weak and it should also check for transactional information. Fixes #266 --- wal2json.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wal2json.c b/wal2json.c index 98cfd1d1c802..323721a87722 100644 --- a/wal2json.c +++ b/wal2json.c @@ -2526,7 +2526,12 @@ pg_decode_message_v1(LogicalDecodingContext *ctx, ReorderBufferTXN *txn, appendStringInfo(ctx->out, "%s%s", data->ht, data->ht); - if (data->nr_changes > 1) + /* + * Non-transactional message contains only one object. Comma is not + * required. Avoid printing a comma for non-transactional messages that was + * provided in a transaction. + */ + if (transactional && data->nr_changes > 1) appendStringInfoChar(ctx->out, ','); appendStringInfo(ctx->out, "{%s%s%s%s\"kind\":%s\"message\",%s", data->nl, data->ht, data->ht, data->ht, data->sp, data->nl);