Skip to content

Commit

Permalink
utils: fix JSON encoding for special characters (#1278 #1415)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jul 3, 2019
1 parent 7698c71 commit 9b00fad
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/flb_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,35 +547,37 @@ int flb_utils_write_str(char *buf, int *off, size_t size,
}

c = (uint32_t) str[i];
if (c == '\\' || c == '"') {
if (c == '\"') {
*p++ = '\\';
*p++ = c;
*p++ = '\"';
}
else if (c >= '\a' && c <= '\r') {
else if (c == '\\') {
*p++ = '\\';
switch (c) {
case '\n':
*p++ = 'n';
break;
case '\t':
*p++ = 't';
break;
case '\b':
*p++ = 'b';
break;
case '\f':
*p++ = 'f';
break;
case '\r':
*p++ = 'r';
break;
case '\a':
*p++ = 'a';
break;
case '\v':
*p++ = 'v';
break;
}
*p++ = '\\';
}
else if (c == '\n') {
*p++ = '\\';
*p++ = 'n';
}
else if (c == '\r') {
*p++ = '\\';
*p++ = 'r';
}
else if (c == '\t') {
*p++ = '\\';
*p++ = 't';
}
else if (c == '\b') {
*p++ = '\\';
*p++ = 'b';
}
else if (c == '\f') {
*p++ = '\\';
*p++ = 'f';
}
else if (c == '/') {
*p++ = '\\';
*p++ = '/';
}
else if (c < 32 || c == 0x7f) {
if ((available - written) < 6) {
Expand Down

0 comments on commit 9b00fad

Please sign in to comment.