Skip to content

Commit 5cd3e84

Browse files
committed
added '/' to the characters escaped in JSON
1 parent f306c51 commit 5cd3e84

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

JSON/src/Stringifier.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
7070
void Stringifier::formatString(const std::string& value, std::ostream& out)
7171
{
7272
out << '"';
73-
for (std::string::const_iterator it = value.begin(); it != value.end(); ++it)
73+
for (std::string::const_iterator it = value.begin(),
74+
end = value.end(); it != end; ++it)
7475
{
75-
if (*it <= 0x1F || *it == '"' || *it == '\\') out << '\\';
76+
if (*it <= 0x1F || *it == '"' || *it == '\\' || *it == '/')
77+
{
78+
out << '\\';
79+
}
7680
out << *it;
7781
}
7882
out << '"';

JSON/testsuite/src/JSONTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ void JSONTest::testStringify()
12311231
std::stringstream ss;
12321232
jObj.stringify(ss);
12331233

1234-
assert(ss.str() == "{\"bar/\":0,\"baz\":0,\"foo\\\\\":0,\"q\\\"uote\\\"d\":0}");
1234+
assert(ss.str() == "{\"bar\\/\":0,\"baz\":0,\"foo\\\\\":0,\"q\\\"uote\\\"d\":0}");
12351235

12361236
std::string json = "{ \"Simpsons\" : { \"husband\" : { \"name\" : \"Homer\" , \"age\" : 38 }, \"wife\" : { \"name\" : \"Marge\", \"age\" : 36 }, "
12371237
"\"children\" : [ \"Bart\", \"Lisa\", \"Maggie\" ], "

0 commit comments

Comments
 (0)