Merge pull request #457 from jplitza/master

luci-lib-jsonc: fix handling of strange keys, allow encoding []
This commit is contained in:
Jo-Philipp Wich 2015-08-30 17:57:00 +02:00
commit a36a73cbdc

View file

@ -222,7 +222,7 @@ static int _lua_test_array(lua_State *L, int index)
out: out:
lua_pop(L, 2); lua_pop(L, 2);
return 0; return -1;
} }
/* check for holes */ /* check for holes */
@ -254,7 +254,7 @@ static struct json_object * _lua_to_json(lua_State *L, int index)
case LUA_TTABLE: case LUA_TTABLE:
max = _lua_test_array(L, index); max = _lua_test_array(L, index);
if (max > 0) if (max >= 0)
{ {
obj = json_object_new_array(); 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); lua_pushvalue(L, -2);
key = lua_tostring(L, -1); key = lua_tostring(L, -1);
json_object_object_add(obj, key, if (key)
_lua_to_json(L, lua_gettop(L) - 1)); json_object_object_add(obj, key,
_lua_to_json(L, lua_gettop(L) - 1));
lua_pop(L, 2); lua_pop(L, 2);
} }