Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly

Tests added.
This commit is contained in:
chenha0
2016-01-21 20:11:40 +08:00
parent 537f8bcbdb
commit dffdee966f
6 changed files with 24 additions and 6 deletions

View File

@@ -123,6 +123,12 @@ static int json_escape_str(struct printbuf *pb, const char *str, int len, int fl
case '"':
case '\\':
case '/':
if((flags & JSON_C_TO_STRING_NOSLASHESCAPE) && c == '/')
{
pos++;
break;
}
if(pos - start_offset > 0)
printbuf_memappend(pb, str + start_offset, pos - start_offset);
@@ -133,12 +139,6 @@ static int json_escape_str(struct printbuf *pb, const char *str, int len, int fl
else if(c == '\f') printbuf_memappend(pb, "\\f", 2);
else if(c == '"') printbuf_memappend(pb, "\\\"", 2);
else if(c == '\\') printbuf_memappend(pb, "\\\\", 2);
else if(c == '/' &&
(flags & JSON_C_TO_STRING_NOSLASHESCAPE))
{
pos++;
break;
}
else if(c == '/') printbuf_memappend(pb, "\\/", 2);
start_offset = ++pos;