unescape: utf8: unescape special characters too
The current implementation only decoded/unescaped \u characters, this
patch extend it support to: \", \\, \/, \n, \a, \b, \t, \v, \f and \r.
@@ -150,9 +150,47 @@ int flb_unescape_string_utf8(const char *in_buf, int sz, char *out_buf)
while (*in_buf && count_in < sz) {
next = in_buf + 1;
- if (*in_buf == '\\' && !is_json_escape(*next)) {
+
+ if (*in_buf == '\\') {
+ if (is_json_escape(*next)) {
+ switch (*next) {
+ case '"':
+ ch = '"';
+ break;
+ case '\\':
+ ch = '\\';
+ break;
+ case '/':
+ ch = '/';
+ break;
+ case 'n':
+ ch = '\n';
+ break;
+ case 'a':
+ ch = '\a';
+ break;
+ case 'b':
+ ch = '\b';
+ break;
+ case 't':
+ ch = '\t';
+ break;
+ case 'v':
+ ch = '\v';
+ break;
+ case 'f':
+ ch = '\f';
+ break;
+ case 'r':
+ ch = '\r';
+ break;
+ }
+ esc_in = 2;
+ }
+ else {
esc_in = u8_read_escape_sequence((in_buf + 1), &ch) + 1;
}
+ }
else {
ch = (uint32_t) *in_buf;
esc_in = 1;
