[notmuch] [PATCH] json_quote_str should handle non-ASCII characters

Gregor Hoffleit gregor at hoffleit.de
Thu Mar 4 02:40:03 PST 2010


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.

This patch accepts code points 32-255.

json_quote_str() should handle non-ASCII characters.
---
 json.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/json.c b/json.c
index 9614143..6dc0345 100644
--- a/json.c
+++ b/json.c
@@ -59,7 +59,7 @@ json_quote_str(const void *ctx, const char *str)
 	return NULL;
 
     for (ptr = str; *ptr; len++, ptr++) {
-	if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
+	if ((unsigned char)(*ptr) < 32 || *ptr == '\"' || *ptr == '\\')
 	    len++;
     }
 
@@ -70,7 +70,7 @@ json_quote_str(const void *ctx, const char *str)
 
     *ptr2++ = '\"';
     while (*ptr) {
-	    if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') {
+	    if ((unsigned char)(*ptr) > 31 && *ptr != '\"' && *ptr != '\\') {
 		*ptr2++ = *ptr++;
 	    } else {
 		*ptr2++ = '\\';
--
1.7.0


More information about the notmuch mailing list