diff --git a/src/foundation/str_util.c b/src/foundation/str_util.c index 6275ab592..26542e927 100644 --- a/src/foundation/str_util.c +++ b/src/foundation/str_util.c @@ -6,6 +6,7 @@ #include "foundation/constants.h" #include #include +#include enum { JSON_ESC_LEN = 2, /* escaped char takes 2 bytes (backslash + char) */ @@ -328,8 +329,11 @@ int cbm_json_escape(char *buf, int bufsize, const char *src) { buf[pos++] = '\\'; buf[pos++] = 't'; } else if (c < JSON_CTRL_LIMIT) { - /* Other control chars: skip */ - continue; + /* Other control chars: escape as \u00XX */ + if (pos + 6 > bufsize - JSON_NUL_RESERVE) { + break; + } + pos += snprintf(buf + pos, 7, "\\u%04x", c); } else { buf[pos++] = (char)c; } diff --git a/src/git/git_context.c b/src/git/git_context.c index 5f27b9f20..99ae17cf3 100644 --- a/src/git/git_context.c +++ b/src/git/git_context.c @@ -316,7 +316,7 @@ static int json_escaped_len(const char *src) { if (c == '"' || c == '\\' || c == '\n' || c == '\r' || c == '\t') { len += 2; } else if (c < 0x20) { - continue; + len += 6; /* \u00XX */ } else { len++; }