]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Restore described behaviour for some lua functions
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 15:06:07 +0000 (15:06 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 15:06:07 +0000 (15:06 +0000)
src/lua/lua_html.c
src/lua/lua_task.c

index 57a46dfb2c0fba9920e53f17c14ad54c0a1ad366..7c5ca3cb9fae35ee2233467f7f74852b4218f5fe 100644 (file)
@@ -249,13 +249,16 @@ lua_html_get_images (lua_State *L)
        if (hc != NULL) {
                lua_newtable (L);
 
-               if (hc->images) {
+               if (hc->images && hc->images->len > 0) {
                        for (i = 0; i < hc->images->len; i ++) {
                                img = g_ptr_array_index (hc->images, i);
                                lua_html_push_image (L, img);
                                lua_rawseti (L, -2, i + 1);
                        }
                }
+               else {
+                       lua_pushnil (L);
+               }
        }
        else {
                lua_pushnil (L);
@@ -275,7 +278,7 @@ lua_html_get_blocks (lua_State *L)
        if (hc != NULL) {
                lua_newtable (L);
 
-               if (hc->blocks) {
+               if (hc->blocks && hc->blocks->len > 0) {
                        for (i = 0; i < hc->blocks->len; i ++) {
                                bl = g_ptr_array_index (hc->blocks, i);
 
@@ -322,6 +325,9 @@ lua_html_get_blocks (lua_State *L)
                                lua_rawseti (L, -2, i + 1);
                        }
                }
+               else {
+                       lua_pushnil (L);
+               }
        }
        else {
                lua_pushnil (L);
index e5214a321936eb229755dc0a6027f741f48f7ca3..fa60184eef438247638f52324f41e5f9d56b2b5f 100644 (file)
@@ -1843,14 +1843,20 @@ lua_task_get_images (lua_State *L)
        if (task) {
                cur = task->images;
 
-               lua_newtable (L);
+               if (cur) {
+                       lua_newtable (L);
 
-               while (cur) {
-                       pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
-                       rspamd_lua_setclass (L, "rspamd{image}", -1);
-                       *pimg = cur->data;
-                       lua_rawseti (L, -2, i++);
-                       cur = g_list_next (cur);
+                       while (cur) {
+                               pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
+                               rspamd_lua_setclass (L, "rspamd{image}", -1);
+                               *pimg = cur->data;
+                               lua_rawseti (L, -2, i++);
+                               cur = g_list_next (cur);
+                       }
+               }
+               else {
+                       /* Return nil if there are no images to preserve compatibility */
+                       lua_pushnil (L);
                }
        }
        else {