summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-08-30 17:57:00 +0200
committerJo-Philipp Wich <jow@openwrt.org>2015-08-30 17:57:00 +0200
commita36a73cbdcfb54e1c23453b2541ca74bf36ee79a (patch)
tree06d874a2e8b01b6e91202b413779d864953fd280
parent0d5070c51089deb448476f1abadcea8e185eaf9b (diff)
parente7645d557c1bd532e49c69f0ab781cf6342067d1 (diff)
Merge pull request #457 from jplitza/master
luci-lib-jsonc: fix handling of strange keys, allow encoding []
-rw-r--r--libs/luci-lib-jsonc/src/jsonc.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
index 49cb21f5bc..971fb122f7 100644
--- a/libs/luci-lib-jsonc/src/jsonc.c
+++ b/libs/luci-lib-jsonc/src/jsonc.c
@@ -222,7 +222,7 @@ static int _lua_test_array(lua_State *L, int index)
out:
lua_pop(L, 2);
- return 0;
+ return -1;
}
/* check for holes */
@@ -254,7 +254,7 @@ static struct json_object * _lua_to_json(lua_State *L, int index)
case LUA_TTABLE:
max = _lua_test_array(L, index);
- if (max > 0)
+ if (max >= 0)
{
obj = json_object_new_array();
@@ -286,8 +286,9 @@ static struct json_object * _lua_to_json(lua_State *L, int index)
lua_pushvalue(L, -2);
key = lua_tostring(L, -1);
- json_object_object_add(obj, key,
- _lua_to_json(L, lua_gettop(L) - 1));
+ if (key)
+ json_object_object_add(obj, key,
+ _lua_to_json(L, lua_gettop(L) - 1));
lua_pop(L, 2);
}