From: Vsevolod Stakhov Date: Sat, 23 Nov 2019 14:27:28 +0000 (+0000) Subject: [Minor] Allow rspamd_text matching in lpeg X-Git-Tag: 2.3~304 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b1a7978b2d29cbbe2ed9d2ebc3a3d30be090be6a;p=thirdparty%2Frspamd.git [Minor] Allow rspamd_text matching in lpeg --- diff --git a/contrib/lua-lpeg/lptree.c b/contrib/lua-lpeg/lptree.c index cb83424592..ffc03f7700 100644 --- a/contrib/lua-lpeg/lptree.c +++ b/contrib/lua-lpeg/lptree.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "lua.h" @@ -1155,9 +1156,25 @@ static int lp_match (lua_State *L) { #endif const char *r; size_t l; + const char *s; + Pattern *p = (getpatt(L, 1, NULL), getpattern(L, 1)); Instruction *code = (p->code != NULL) ? p->code : prepcompile(L, p, 1); - const char *s = luaL_checklstring(L, SUBJIDX, &l); + + if (lua_type (L, SUBJIDX) == LUA_TSTRING) { + s = luaL_checklstring (L, SUBJIDX, &l); + } + else if (lua_type (L, SUBJIDX) == LUA_TUSERDATA) { + struct rspamd_lua_text *t = lua_check_text (L, SUBJIDX); + if (!t) { + return luaL_error (L, "invalid argument (not a text)"); + } + s = t->start; + l = t->len; + } + else { + return luaL_error (L, "invalid argument"); + } size_t i = initposition(L, l); int ptop = lua_gettop(L), rs; lua_pushnil(L); /* initialize subscache */