From 975dbd4042f753b7a1e6dd819d0f70d8fd8f52f9 Mon Sep 17 00:00:00 2001 From: Sergey 'Jin' Bostandzhyan Date: Thu, 24 Jul 2014 09:49:13 +0200 Subject: [PATCH] Handle % character properly For *printf kind of functions through which the string seems to go somewhere in the depths of json-c '%' needs to be esacped to %%. --- json_object.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json_object.c b/json_object.c index 8ed0239..34578d9 100644 --- a/json_object.c +++ b/json_object.c @@ -114,6 +114,7 @@ static int json_escape_str(struct printbuf *pb, char *str, int len) case '"': case '\\': case '/': + case '%': if(pos - start_offset > 0) printbuf_memappend(pb, str + start_offset, pos - start_offset); @@ -125,6 +126,7 @@ static int json_escape_str(struct printbuf *pb, char *str, int len) else if(c == '"') printbuf_memappend(pb, "\\\"", 2); else if(c == '\\') printbuf_memappend(pb, "\\\\", 2); else if(c == '/') printbuf_memappend(pb, "\\/", 2); + else if(c == '%') printbuf_memappend(pb, "%%", 2); start_offset = ++pos; break;