]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-lua: Change dict:lookup() to actually return nil if key isn't found
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 10 Sep 2021 12:47:47 +0000 (15:47 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Thu, 16 Sep 2021 13:59:54 +0000 (13:59 +0000)
It was previously returning an empty table, although the comment said it
should have returned nil.

src/lib-dict/dict-lua.c

index 1be6b61fa4bdda4ddcb5a6117c273f55a95963b2..abab8c7f93326bd89d245bb9c9ae31005f057ed9 100644 (file)
@@ -27,11 +27,11 @@ static int lua_dict_async_continue(lua_State *L,
                                   lua_KContext ctx ATTR_UNUSED)
 {
        /*
-        * lua_dict_*_callback() already pushed the result table or error
+        * lua_dict_*_callback() already pushed the result table/nil or error
         * string.  We simply need to return/error out.
         */
 
-       if (lua_istable(L, -1))
+       if (lua_istable(L, -1) || lua_isnil(L, -1))
                return 1;
        else
                return lua_error(L);
@@ -42,6 +42,8 @@ static void lua_dict_lookup_callback(const struct dict_lookup_result *result,
 {
        if (result->ret < 0) {
                lua_pushstring(L, result->error);
+       } else if (result->ret == 0) {
+               lua_pushnil(L);
        } else {
                unsigned int i;