diff --git a/lib/filterx/func-flatten.c b/lib/filterx/func-flatten.c index bcda2ec8f..444bd3d49 100644 --- a/lib/filterx/func-flatten.c +++ b/lib/filterx/func-flatten.c @@ -76,7 +76,7 @@ _collect_modifications_from_elem(FilterXObject *key, FilterXObject *value, gpoin if (filterx_object_is_type(dict, &FILTERX_TYPE_NAME(dict))) { if (is_top_level) - *top_level_dict_keys = g_list_prepend(*top_level_dict_keys, filterx_object_ref(key)); + *top_level_dict_keys = g_list_append(*top_level_dict_keys, filterx_object_ref(key)); gssize orig_len = key_buffer->len; if (!filterx_object_repr_append(key, key_buffer)) @@ -108,7 +108,7 @@ _collect_modifications_from_elem(FilterXObject *key, FilterXObject *value, gpoin } FilterXObject *flat_key = filterx_string_new(key_buffer->str, (gssize) MIN(key_buffer->len, G_MAXSSIZE)); - *flattened_kvs = g_list_prepend(*flattened_kvs, _kv_new(flat_key, value)); + *flattened_kvs = g_list_append(*flattened_kvs, _kv_new(flat_key, value)); filterx_object_unref(flat_key); g_string_truncate(key_buffer, orig_len); diff --git a/lib/filterx/tests/test_func_flatten.c b/lib/filterx/tests/test_func_flatten.c index 16f30096f..996bb6615 100644 --- a/lib/filterx/tests/test_func_flatten.c +++ b/lib/filterx/tests/test_func_flatten.c @@ -111,7 +111,7 @@ Test(filterx_func_flatten, default_separator) GList *args = g_list_append(NULL, filterx_function_arg_new(NULL, filterx_literal_new(filterx_json_new_from_repr(input, -1)))); _assert_flatten(args, - "{\"top_level_field\":42,\"top_level_dict.inner_dict.inner_inner_field\":1,\"top_level_dict.inner_field\":1337}"); + "{\"top_level_field\":42,\"top_level_dict.inner_field\":1337,\"top_level_dict.inner_dict.inner_inner_field\":1}"); } Test(filterx_func_flatten, custom_separator) @@ -122,7 +122,7 @@ Test(filterx_func_flatten, custom_separator) filterx_literal_new(filterx_json_new_from_repr(input, -1)))); args = g_list_append(args, filterx_function_arg_new("separator", filterx_literal_new(filterx_string_new("->", -1)))); _assert_flatten(args, - "{\"top_level_field\":42,\"top_level_dict->inner_dict->inner_inner_field\":1,\"top_level_dict->inner_field\":1337}"); + "{\"top_level_field\":42,\"top_level_dict->inner_field\":1337,\"top_level_dict->inner_dict->inner_inner_field\":1}"); } static void diff --git a/tests/light/functional_tests/filterx/test_filterx.py b/tests/light/functional_tests/filterx/test_filterx.py index b6e6200c5..22309a51f 100644 --- a/tests/light/functional_tests/filterx/test_filterx.py +++ b/tests/light/functional_tests/filterx/test_filterx.py @@ -1956,8 +1956,8 @@ def test_flatten(config, syslog_ng): assert file_true.get_stats()["processed"] == 1 assert "processed" not in file_false.get_stats() assert file_true.read_log() == '[' \ - '{"top_level_field":42,"top_level_dict.inner_dict.inner_inner_field":1,"top_level_dict.inner_field":1337},' \ - '{"top_level_field":42,"top_level_dict->inner_dict->inner_inner_field":1,"top_level_dict->inner_field":1337}' \ + '{"top_level_field":42,"top_level_dict.inner_field":1337,"top_level_dict.inner_dict.inner_inner_field":1},' \ + '{"top_level_field":42,"top_level_dict->inner_field":1337,"top_level_dict->inner_dict->inner_inner_field":1}' \ ']\n'