Browse Source

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 %%.
pull/145/head
Sergey 'Jin' Bostandzhyan 11 years ago
parent
commit
975dbd4042
1 changed files with 2 additions and 0 deletions
  1. +2
    -0
      json_object.c

+ 2
- 0
json_object.c View File

@@ -114,6 +114,7 @@ static int json_escape_str(struct printbuf *pb, char *str, int len)
case '"': case '"':
case '\\': case '\\':
case '/': case '/':
case '%':
if(pos - start_offset > 0) if(pos - start_offset > 0)
printbuf_memappend(pb, str + start_offset, pos - start_offset); 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);
else if(c == '/') printbuf_memappend(pb, "\\/", 2); else if(c == '/') printbuf_memappend(pb, "\\/", 2);
else if(c == '%') printbuf_memappend(pb, "%%", 2);


start_offset = ++pos; start_offset = ++pos;
break; break;


Loading…
Cancel
Save