From: erickson Date: Sun, 13 Mar 2005 19:38:16 +0000 (+0000) Subject: added escaping for internal " characters X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d2e07e03657a83f6f2b62a279c2a464bf44a8e24;p=opensrf%2Fbjwebb.git added escaping for internal " characters git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@221 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/libjson/json_object.c b/src/libjson/json_object.c index 358b998..b11e4c5 100644 --- a/src/libjson/json_object.c +++ b/src/libjson/json_object.c @@ -91,12 +91,14 @@ static int json_escape_str(struct printbuf *pb, char *str) case '\n': case '\r': case '\t': + case '"': if(pos - start_offset > 0) printbuf_memappend(pb, str + start_offset, pos - start_offset); if(c == '\b') printbuf_memappend(pb, "\\b", 2); else if(c == '\n') printbuf_memappend(pb, "\\n", 2); else if(c == '\r') printbuf_memappend(pb, "\\r", 2); else if(c == '\t') printbuf_memappend(pb, "\\t", 2); + else if(c == '"') printbuf_memappend(pb, "\\\"", 2); start_offset = ++pos; break; default: diff --git a/src/libjson/printbuf.c b/src/libjson/printbuf.c index 1dfbccd..d05cd26 100644 --- a/src/libjson/printbuf.c +++ b/src/libjson/printbuf.c @@ -55,7 +55,15 @@ int printbuf_memappend(struct printbuf *p, char *buf, int size) p->size = new_size; p->buf = t; } - memcpy(p->buf + p->bpos, buf, size); + + char* tmp = strdup(p->buf); + memset( p->buf, 0, p->size); + memcpy( p->buf, tmp, strlen(tmp)); + memcpy(p->buf + p->bpos, buf, size); + free(tmp); + + +// memcpy(p->buf + p->bpos, buf, size); p->bpos += size; p->buf[p->bpos]= '\0'; return size;