utils: fix JSON encoding for special characters
@@ -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++ = '\"';
+ }
+ else if (c == '\\') {
+ *p++ = '\\';
*p++ = '\\';
- *p++ = c;
}
- else if (c >= '\a' && c <= '\r') {
+ else if (c == '\n') {
*p++ = '\\';
- switch (c) {
- case '\n':
*p++ = 'n';
- break;
- case '\t':
+ }
+ else if (c == '\r') {
+ *p++ = '\\';
+ *p++ = 'r';
+ }
+ else if (c == '\t') {
+ *p++ = '\\';
*p++ = 't';
- break;
- case '\b':
+ }
+ else if (c == '\b') {
+ *p++ = '\\';
*p++ = 'b';
- break;
- case '\f':
+ }
+ else if (c == '\f') {
+ *p++ = '\\';
*p++ = 'f';
- break;
- case '\r':
- *p++ = 'r';
- break;
- case '\a':
- *p++ = 'a';
- break;
- case '\v':
- *p++ = 'v';
- break;
}
+ else if (c == '/') {
+ *p++ = '\\';
+ *p++ = '/';
}
else if (c < 32 || c == 0x7f) {
if ((available - written) < 6) {
