diff options
author | chenha0 <gary.haochen@gmail.com> | 2016-01-21 20:11:40 +0800 |
---|---|---|
committer | chenha0 <gary.haochen@gmail.com> | 2016-01-21 20:12:48 +0800 |
commit | dffdee966f03a7039b8d8fa5d5c4eb048ef31749 (patch) | |
tree | 65d827c1bcadecbe3cd6d29a555d1511da1ae171 /json_object.c | |
parent | 537f8bcbdbdc10ffa7673199a0be82ca4eb56ec8 (diff) | |
download | json-c-dffdee966f03a7039b8d8fa5d5c4eb048ef31749.tar.gz |
Fix issue #221: JSON_C_TO_STRING_NOSLASHESCAPE works incorrectly
Tests added.
Diffstat (limited to 'json_object.c')
-rw-r--r-- | json_object.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/json_object.c b/json_object.c index e611103..3ee0817 100644 --- a/json_object.c +++ b/json_object.c @@ -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; |