aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-23 14:27:28 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-11-25 12:35:06 +0000
commitb1a7978b2d29cbbe2ed9d2ebc3a3d30be090be6a (patch)
treedb67a71b58312d1bcb406ef1843f941040ba98a0
parenta0a27b8744fe9767105841925785f8d54781bc19 (diff)
downloadrspamd-b1a7978b2d29cbbe2ed9d2ebc3a3d30be090be6a.tar.gz
rspamd-b1a7978b2d29cbbe2ed9d2ebc3a3d30be090be6a.zip
[Minor] Allow rspamd_text matching in lpeg
-rw-r--r--contrib/lua-lpeg/lptree.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/contrib/lua-lpeg/lptree.c b/contrib/lua-lpeg/lptree.c
index cb8342459..ffc03f770 100644
--- a/contrib/lua-lpeg/lptree.c
+++ b/contrib/lua-lpeg/lptree.c
@@ -6,6 +6,7 @@
#include <ctype.h>
#include <limits.h>
#include <string.h>
+#include <src/lua/lua_common.h>
#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 */