]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Make tostring in UCL a bit less brain-damaged
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 13 Aug 2024 14:07:06 +0000 (15:07 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 13 Aug 2024 14:07:06 +0000 (15:07 +0100)
contrib/libucl/lua_ucl.c

index 3e3a06605671e07153320ad193da8e383951a00b..79c6586159a3edf75db8fb1ccc4c141680585b49 100644 (file)
@@ -1146,8 +1146,9 @@ lua_ucl_object_tostring(lua_State *L)
        enum ucl_emitter format = UCL_EMIT_JSON_COMPACT;
 
        obj = lua_ucl_object_get(L, 1);
+       int type = ucl_object_type(obj);
 
-       if (obj) {
+       if (type == UCL_ARRAY || type == UCL_OBJECT) {
                if (lua_gettop(L) > 1) {
                        if (lua_type(L, 2) == LUA_TSTRING) {
                                const char *strtype = lua_tostring(L, 2);
@@ -1158,9 +1159,12 @@ lua_ucl_object_tostring(lua_State *L)
 
                return lua_ucl_to_string(L, obj, format);
        }
-       else {
+       else if (type == UCL_NULL) {
                lua_pushnil(L);
        }
+       else {
+               ucl_object_lua_push_scalar(L, obj, 0);
+       }
 
        return 1;
 }