Browse Source

[Minor] Fix some more issues

tags/2.6
Vsevolod Stakhov 4 years ago
parent
commit
8aae3eae77
2 changed files with 7 additions and 8 deletions
  1. 2
    3
      src/lua/lua_expression.c
  2. 5
    5
      test/lua/unit/expressions.lua

+ 2
- 3
src/lua/lua_expression.c View File

@@ -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");


+ 5
- 5
test/lua/unit/expressions.lua View File

@@ -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'",

Loading…
Cancel
Save