diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/common.c b/src/common.c index aa75c198..5a953672 100644 --- a/src/common.c +++ b/src/common.c @@ -227,9 +227,18 @@ void json_escape_string(char *dst, const char *src, size_t size) { } void json_fix_string(char *s) { - for( ; *s ;s++) { - if(unlikely(*s == '\\')) *s = '/'; - else if(unlikely(*s == '"')) *s = '\''; + unsigned char c; + while((c = (unsigned char)*s)) { + if(unlikely(c == '\\')) + *s++ = '/'; + else if(unlikely(c == '"')) + *s++ = '\''; + else if(unlikely(isspace(c) || iscntrl(c))) + *s++ = ' '; + else if(unlikely(!isprint(c) || c > 127)) + *s++ = '_'; + else + s++; } } |