]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: fix serialization of empty nested tables
authorMarek Vavrusa <marek@vavrusa.com>
Fri, 27 May 2016 07:33:54 +0000 (00:33 -0700)
committerMarek Vavrusa <marek@vavrusa.com>
Thu, 16 Jun 2016 17:15:19 +0000 (10:15 -0700)
daemon/engine.c

index 774fb8cbdbf2f14b809f2c8d1b7195b7ec5019cf..7f1529f562971e859c71fdfd0a881615d7b37be2 100644 (file)
@@ -289,23 +289,24 @@ static JsonNode *l_pack_elem(lua_State *L, int top)
        JsonNode *node = NULL;
        lua_pushnil(L);
        while(lua_next(L, top) != 0) {
-               JsonNode *val = l_pack_elem(L, top + 2);
-               const bool no_key = lua_isnumber(L, top + 1);
+               const bool is_array = lua_isnumber(L, top + 1);
                if (!node) {
-                       node = no_key ? json_mkarray() : json_mkobject();
+                       node = is_array ? json_mkarray() : json_mkobject();
                        if (!node) {
                                return NULL;
                        }
                }
-               /* Insert to array/table */
-               if (no_key) {
+               /* Insert to array/table. */
+               JsonNode *val = l_pack_elem(L, top + 2);
+               if (is_array) {
                        json_append_element(node, val);
                } else {
                        json_append_member(node, lua_tostring(L, top + 1), val);
                }
                lua_pop(L, 1);
        }
-       return node;
+       /* Return empty object for empty tables. */
+       return node ? node : json_mkobject();
 }
 
 /** @internal Serialize to string */