Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiterx json array fix - unwanted NULL results in get_subscript #273

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/filterx/object-json-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ _get_subscript(FilterXList *s, guint64 index)
FilterXJsonArray *self = (FilterXJsonArray *) s;

struct json_object *jso = json_object_array_get_idx(self->jso, index);
if (!jso)
{
/* NULL is returned if the stored value is null. */
if (json_object_array_length(self->jso) > index + 1)
return NULL;
}

return filterx_json_convert_json_to_object_cached(&s->super, &self->root_container, jso);
}
Expand Down
31 changes: 31 additions & 0 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,3 +2008,34 @@ def test_get_sdata(config, syslog_ng):
},
},
}


def test_list_range_check_with_nulls(config, syslog_ng):
(file_true, file_false) = create_config(
config, r"""
$MSG = json();
js1 = json_array([null]);
js2 = json_array([null, "bar"]);
$MSG.caseA = js1[0];
$MSG.caseB = js2[0];
$MSG.caseC = js2[1];
""",
)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert "processed" not in file_false.get_stats()
assert file_true.read_log() == '{"caseA":null,"caseB":null,"caseC":"bar"}\n'


def test_list_range_check_out_of_range(config, syslog_ng):
(file_true, file_false) = create_config(
config, r"""
$MSG = json();
js1 = json_array([null, "bar"]);
$MSG.caseA = js1[2];
""",
)
syslog_ng.start(config)
assert file_false.get_stats()["processed"] == 1
assert file_false.read_log() == "foobar\n"
Loading