]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Support unpack for text
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Sep 2019 12:59:19 +0000 (13:59 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Sep 2019 12:59:19 +0000 (13:59 +0100)
src/lua/lua_util.c

index e18912e9a3b25dbb6a56b671845a9bb9b6e8e831..c25d20471746799eaae8ab6b9e184737238e6b25 100644 (file)
@@ -3715,11 +3715,28 @@ lua_util_unpack (lua_State *L)
        Header h;
        const char *fmt = luaL_checkstring(L, 1);
        size_t ld;
-       const char *data = luaL_checklstring (L, 2, &ld);
-       size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1;
+       const char *data;
        int n = 0;  /* number of results */
+
+       if (lua_type (L, 2) == LUA_TUSERDATA) {
+               struct rspamd_lua_text *t = lua_check_text (L, 2);
+
+               if (!t) {
+                       return luaL_error (L, "invalid arguments");
+               }
+
+               data = t->start;
+               ld = t->len;
+       }
+       else {
+               data = luaL_checklstring (L, 2, &ld);
+       }
+
+       size_t pos = (size_t) posrelat (luaL_optinteger (L, 3, 1), ld) - 1;
        luaL_argcheck(L, pos <= ld, 3, "initial position out of string");
+
        initheader (L, &h);
+
        while (*fmt != '\0') {
                int size, ntoalign;
                KOption opt = getdetails (&h, pos, &fmt, &size, &ntoalign);