commit b2bf127: [Minor] Lua_logger: Fix printing of sparse tables
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Jan 20 17:21:06 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-01-20 17:14:13 +0000
URL: https://github.com/rspamd/rspamd/commit/b2bf127b542325e59229f98b518b4be8d49573e7 (HEAD -> master)
[Minor] Lua_logger: Fix printing of sparse tables
---
src/lua/lua_logger.c | 21 ++++++++++++++++++---
1 file 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);
More information about the Commits
mailing list