aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 15:06:07 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 15:06:07 +0000
commitf5955b8d3e46fef5065a395ce3f7dade267fba1f (patch)
tree13d698a7ecd6aed603a048fe478cd3fb630a788b
parentb4fbb32b3dcd21f1fc90c419aa3992ecb6f7924a (diff)
downloadrspamd-f5955b8d3e46fef5065a395ce3f7dade267fba1f.tar.gz
rspamd-f5955b8d3e46fef5065a395ce3f7dade267fba1f.zip
[Fix] Restore described behaviour for some lua functions
-rw-r--r--src/lua/lua_html.c10
-rw-r--r--src/lua/lua_task.c20
2 files changed, 21 insertions, 9 deletions
diff --git a/src/lua/lua_html.c b/src/lua/lua_html.c
index 57a46dfb2..7c5ca3cb9 100644
--- a/src/lua/lua_html.c
+++ b/src/lua/lua_html.c
@@ -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);
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index e5214a321..fa60184ee 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -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 {