aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-20 17:14:13 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-01-20 17:14:13 +0000
commitb2bf127b542325e59229f98b518b4be8d49573e7 (patch)
tree256abf62b0305a3081d60371c9be9ba63a7d83ff /src/lua
parentc4cdc7a35003eafb1baa2a3bf5f1c48d89465e63 (diff)
downloadrspamd-b2bf127b542325e59229f98b518b4be8d49573e7.tar.gz
rspamd-b2bf127b542325e59229f98b518b4be8d49573e7.zip
[Minor] Lua_logger: Fix printing of sparse tables
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_logger.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index f76db8877..7902babb8 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -463,7 +463,7 @@ lua_logger_out_table (lua_State *L, gint pos, gchar *outbuf, gsize len,
gsize remain = len, r;
gboolean first = TRUE;
gconstpointer self = NULL;
- gint i, tpos;
+ gint i, tpos, last_seq = -1;
if (!lua_istable (L, pos) || remain == 0) {
return 0;
@@ -498,6 +498,8 @@ lua_logger_out_table (lua_State *L, gint pos, gchar *outbuf, gsize len,
break;
}
+ last_seq = i;
+
if (!first) {
r = rspamd_snprintf (d, remain + 1, ", ");
MOVE_BUF(d, remain, r);
@@ -524,7 +526,17 @@ lua_logger_out_table (lua_State *L, gint pos, gchar *outbuf, gsize len,
/* 'key' is at index -2 and 'value' is at index -1 */
if (lua_type (L, -2) == LUA_TNUMBER) {
- continue;
+ if (last_seq > 0) {
+ lua_pushvalue (L, -2);
+
+ if (lua_tonumber (L, -1) <= last_seq + 1) {
+ lua_pop (L, 1);
+ /* Already seen */
+ continue;
+ }
+
+ lua_pop (L, 1);
+ }
}
if (!first) {
@@ -532,8 +544,11 @@ lua_logger_out_table (lua_State *L, gint pos, gchar *outbuf, gsize len,
MOVE_BUF(d, remain, r);
}
+ /* Preserve key */
+ lua_pushvalue (L, -2);
r = rspamd_snprintf (d, remain + 1, "[%s] = ",
- lua_tostring (L, -2));
+ lua_tostring (L, -1));
+ lua_pop (L, 1); /* Remove key */
MOVE_BUF(d, remain, r);
tpos = lua_gettop (L);