Skip to content

Commit

Permalink
Merge pull request #273 from bshifter/fiterx-json-array-fix
Browse files Browse the repository at this point in the history
Fiterx json array fix - unwanted NULL results in get_subscript
  • Loading branch information
alltilla authored Sep 4, 2024
2 parents ab7b626 + 8881661 commit e379056
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
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"

0 comments on commit e379056

Please sign in to comment.