Skip to content

Commit

Permalink
parser: logfmt: fix handling of empty string and null value (#1737)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Dec 10, 2019
1 parent 45d5b20 commit 9688fc4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/flb_parser_logfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -101,13 +102,15 @@ 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++;
if (c < end) {
if (*c == '"') {
c++;
value = c;
value_str = FLB_TRUE;
while (c < end) {
if (*c != '\\' && *c!= '"') {
c++;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9688fc4

Please sign in to comment.