'"' needs to be escaped too in json

This commit is contained in:
Willem Toorop 2019-02-15 10:44:49 +01:00
parent c3d0afd47d
commit 71b773ab2f
1 changed files with 8 additions and 2 deletions

View File

@ -790,12 +790,18 @@ getdns_pp_bindata(gldns_buffer *buf, getdns_bindata *bindata,
if (!gldns_buffer_reserve(buf, (e - s) + 2)) if (!gldns_buffer_reserve(buf, (e - s) + 2))
return -1; return -1;
gldns_buffer_write_u8(buf, '"'); gldns_buffer_write_u8(buf, '"');
while ((b = memchr(s, '\\', e - s))) { for (;;) {
for ( b = s
; b < e && *b != '\\' && *b != '"'
; b++)
; /* pass */
if (b == e)
break;
if (!gldns_buffer_reserve(buf, (b - s) + 3)) if (!gldns_buffer_reserve(buf, (b - s) + 3))
return -1; return -1;
gldns_buffer_write(buf, s, b - s); gldns_buffer_write(buf, s, b - s);
gldns_buffer_write_u8(buf, '\\'); gldns_buffer_write_u8(buf, '\\');
gldns_buffer_write_u8(buf, '\\'); gldns_buffer_write_u8(buf, *b);
s = b + 1; s = b + 1;
} }
if (s < e) if (s < e)