From 8aae3eae774dae1e56e6b401b42aa20bd777112d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 17 Jun 2020 11:05:40 +0100 Subject: [PATCH] [Minor] Fix some more issues --- src/lua/lua_expression.c | 5 ++--- test/lua/unit/expressions.lua | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lua/lua_expression.c b/src/lua/lua_expression.c index b2addd30c..8c44eba08 100644 --- a/src/lua/lua_expression.c +++ b/src/lua/lua_expression.c @@ -352,7 +352,6 @@ lua_expr_create (lua_State *L) if (lua_type (L, 1) != LUA_TSTRING || (lua_type (L, 2) != LUA_TTABLE && lua_type (L, 2) != LUA_TFUNCTION) || rspamd_lua_check_mempool (L, 3) == NULL) { - msg_info ("bad arguments to lua_expr_create"); lua_pushnil (L); lua_pushstring (L, "bad arguments"); } @@ -371,7 +370,7 @@ lua_expr_create (lua_State *L) lua_gettable (L, -2); if (lua_type (L, -1) != LUA_TFUNCTION) { - lua_pop (L, 2); + lua_pop (L, 1); lua_pushnil (L); lua_pushstring (L, "bad parse callback"); @@ -385,7 +384,7 @@ lua_expr_create (lua_State *L) if (lua_type (L, -1) != LUA_TFUNCTION) { if (lua_type (L, -1) != LUA_TNIL && lua_type (L, -1) != LUA_TNONE) { - lua_pop (L, 2); + lua_pop (L, 1); lua_pushnil (L); lua_pushstring (L, "bad process callback"); diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua index 8633560ba..ce6c92dca 100644 --- a/test/lua/unit/expressions.lua +++ b/test/lua/unit/expressions.lua @@ -48,10 +48,10 @@ context("Rspamd expressions", function() {'(((A))', nil}, -- Balanced braces {'(((A)))', '(A)'}, - -- Plus and comparison operators - {'A + B + C + D > 2', '2 (A) (B) (C) (D) +(4) >'}, + -- Plus and comparison operators (after 2.6 this is not optimized, maybe we can return previous behaviour some day) + {'A + B + C + D > 2', '(A) (B) (C) (D) + + + 2 >'}, -- Plus and logic operators - {'((A + B + C + D) > 2) & D', '(D) 2 (A) (B) (C) (D) +(4) > &'}, + {'((A + B + C + D) > 2) & D', '(D) (A) (B) (C) (D) +(4) 2 > &'}, -- Associativity {'A | B | C & D & E', '(A) (B) (C) (D) (E) &(3) |(3)'}, -- More associativity @@ -68,7 +68,7 @@ context("Rspamd expressions", function() if not c[2] then assert_nil(expr, "Should not be able to parse " .. c[1]) else - assert_not_nil(expr, "Cannot parse " .. c[1]) + assert_not_nil(expr, "Cannot parse " .. c[1] .. '; error: ' .. (err or 'wut??')) assert_equal(expr:to_string(), c[2], string.format("Evaluated expr to '%s', expected: '%s'", expr:to_string(), c[2])) end @@ -99,7 +99,7 @@ context("Rspamd expressions", function() local expr,err = rspamd_expression.create(c[1], {parse_func, process_func}, pool) - assert_not_nil(expr, "Cannot parse " .. c[1]) + assert_not_nil(expr, "Cannot parse " .. c[1] .. '; error: ' .. (err or 'wut??')) --print(expr) res = expr:process(atoms) assert_equal(res, c[2], string.format("Processed expr '%s'{%s} returned '%d', expected: '%d'", -- 2.39.5