From: Vsevolod Stakhov Date: Tue, 24 Mar 2015 17:30:00 +0000 (+0000) Subject: Fix some priority issues in expressions. X-Git-Tag: 0.9.0~432 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4442c05a65fbba59822a99da0138409dc4351618;p=rspamd.git Fix some priority issues in expressions. --- diff --git a/src/libutil/expression.c b/src/libutil/expression.c index 350a9aebf..5c057734c 100644 --- a/src/libutil/expression.c +++ b/src/libutil/expression.c @@ -110,20 +110,22 @@ rspamd_expr_logic_priority (enum rspamd_expression_op op) switch (op) { case OP_NOT: - ret = 5; - break; - case OP_MULT: - case OP_AND: - ret = 4; + ret = 6; break; case OP_PLUS: - case OP_OR: - ret = 3; + ret = 5; break; case OP_GE: case OP_GT: case OP_LE: case OP_LT: + ret = 4; + break; + case OP_MULT: + case OP_AND: + ret = 3; + break; + case OP_OR: ret = 2; break; case OP_OBRACE: @@ -322,6 +324,7 @@ rspamd_parse_expression (const gchar *line, gsize len, len = strlen (line); } + memset (&elt, 0, sizeof (elt)); num_re = rspamd_regexp_cache_create (NULL, "/^\\d+(\\s+|[)]|$)/", NULL, NULL); p = line; diff --git a/test/lua/unit/expressions.lua b/test/lua/unit/expressions.lua index 257768618..d75e09ebb 100644 --- a/test/lua/unit/expressions.lua +++ b/test/lua/unit/expressions.lua @@ -60,7 +60,7 @@ context("Rspamd expressions", function() test("Expression process function", function() local function process_func(token, input) - print(token) + --print(token) local t = input[token] if t then return 1 end @@ -81,6 +81,8 @@ context("Rspamd expressions", function() {'A & (!B | C)', 1}, {'A + B + C + D + E + F >= 2', 1}, {'((A + B + C + D) > 1) & F', 0}, + {'(A + B + C + D) > 1 && F || E', 1}, + {'(A + B + C + D) > 100 && F || !E', 0}, {'!!C', 1}, } for _,c in ipairs(cases) do @@ -88,6 +90,7 @@ context("Rspamd expressions", function() {parse_func, process_func}, pool) assert_not_nil(expr, "Cannot parse " .. c[1]) + --print(expr) res = expr:process(atoms) assert_equal(res, c[2], string.format("Processed expr '%s' returned '%d', expected: '%d'", expr:to_string(), res, c[2]))