mirror of
https://github.com/json-c/json-c.git
synced 2026-03-27 00:49:07 +08:00
Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly
Tests added.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user