mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 09:24:54 +01:00
Fix json_quote_str to handle non-ASCII characters
The current code in json_quote_str() only accepts strict printable ASCII code points (i.e. 32-127), all other code points are dropped from the JSON output. The code is attempting to drop only non-printable ASCII characters, but doing a signed comparison of the byte value is also dropping characters with values >= 128. This patch uses an unsigned comparison to accept code points 32-255. Reviewed-by: Carl Worth <cworth@cworth.org> (with some additional details for commit message).
This commit is contained in:
parent
22d117d144
commit
4a44284692
1 changed files with 2 additions and 2 deletions
4
json.c
4
json.c
|
@ -63,7 +63,7 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len)
|
|||
for (loop = 0, required = 0, ptr = str;
|
||||
loop < len;
|
||||
loop++, required++, ptr++) {
|
||||
if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
|
||||
if ((unsigned char)(*ptr) < 32 || *ptr == '\"' || *ptr == '\\')
|
||||
required++;
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len)
|
|||
|
||||
*ptr2++ = '\"';
|
||||
for (loop = 0; loop < len; loop++) {
|
||||
if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') {
|
||||
if ((unsigned char)(*ptr) > 31 && *ptr != '\"' && *ptr != '\\') {
|
||||
*ptr2++ = *ptr++;
|
||||
} else {
|
||||
*ptr2++ = '\\';
|
||||
|
|
Loading…
Reference in a new issue