From 9688fc450ff398f8ea8383ea6f8e0d3ba49de33a Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 10 Dec 2019 17:34:27 -0600 Subject: [PATCH] parser: logfmt: fix handling of empty string and null value (#1737) Signed-off-by: Eduardo Silva --- src/flb_parser_logfmt.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/flb_parser_logfmt.c b/src/flb_parser_logfmt.c index 76c0c2139f3..0103775c5fb 100644 --- a/src/flb_parser_logfmt.c +++ b/src/flb_parser_logfmt.c @@ -78,6 +78,7 @@ static int logfmt_parser(struct flb_parser *parser, const unsigned char *end = c + in_size; int last_byte; int do_pack = FLB_TRUE; + int value_str = FLB_FALSE; int value_escape = FLB_FALSE; /* if map_size is 0 only count the number of k:v */ @@ -101,6 +102,7 @@ static int logfmt_parser(struct flb_parser *parser, key_len = c - key; /* value */ value_len = 0; + value_str = FLB_FALSE; value_escape = FLB_FALSE; if (*c == '=') { c++; @@ -108,6 +110,7 @@ static int logfmt_parser(struct flb_parser *parser, if (*c == '"') { c++; value = c; + value_str = FLB_TRUE; while (c < end) { if (*c != '\\' && *c!= '"') { c++; @@ -171,7 +174,12 @@ static int logfmt_parser(struct flb_parser *parser, msgpack_pack_str(tmp_pck, key_len); msgpack_pack_str_body(tmp_pck, (const char *)key, key_len); if (value_len == 0) { - msgpack_pack_true(tmp_pck); + if (value_str == FLB_TRUE) { + msgpack_pack_str(tmp_pck, 0); + } + else { + msgpack_pack_nil(tmp_pck); + } } else { if (value_escape == FLB_TRUE) {