0004-luci-lib-jsonc-allow-encoding-empty-lists.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. From: Jan-Philipp Litza <janphilipp@litza.de>
  2. Date: Sun, 30 Aug 2015 15:45:49 +0200
  3. Subject: luci-lib-jsonc: allow encoding empty lists
  4. To be consistent with the behavior of luci-lib-json, an empty Lua table
  5. should be encoded to an empty JSON list, not an empty JSON object.
  6. To still allow encoding empty JSON objects, the usage of anything other
  7. than a number or a string as a key (for example an empty table or a
  8. function) can be used to force encoding as an object:
  9. json.stringify({}) -- "[]"
  10. json.stringify({[{}] = true}) -- "{}"
  11. Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
  12. diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
  13. index 827fde8..971fb12 100644
  14. --- a/libs/luci-lib-jsonc/src/jsonc.c
  15. +++ b/libs/luci-lib-jsonc/src/jsonc.c
  16. @@ -222,7 +222,7 @@ static int _lua_test_array(lua_State *L, int index)
  17. out:
  18. lua_pop(L, 2);
  19. - return 0;
  20. + return -1;
  21. }
  22. /* check for holes */
  23. @@ -254,7 +254,7 @@ static struct json_object * _lua_to_json(lua_State *L, int index)
  24. case LUA_TTABLE:
  25. max = _lua_test_array(L, index);
  26. - if (max > 0)
  27. + if (max >= 0)
  28. {
  29. obj = json_object_new_array();