1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

JSON: Support escape special chars. (#1758) v4.0.182

This commit is contained in:
xmedia-systems 2021-10-20 08:57:40 +08:00 committed by winlin
parent 061d544195
commit 34b968aabf
4 changed files with 90 additions and 7 deletions

View file

@ -2626,6 +2626,72 @@ VOID TEST(ProtocolJSONTest, Dumps)
}
}
VOID TEST(ProtocolJSONTest, DumpsSpecialChars)
{
if (true) {
SrsJsonAny* p = SrsJsonAny::str("hello");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"hello\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\"llo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\\"llo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\\llo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\\\llo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\nllo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\nllo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\tllo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\tllo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\bllo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\bllo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\fllo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\fllo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("he\rllo");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"he\\rllo\"", p->dumps().c_str());
srs_freep(p);
}
if (true) {
SrsJsonAny* p = SrsJsonAny::str("hello视频");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"hello\xE8\xA7\x86\xE9\xA2\x91\"", p->dumps().c_str());
srs_freep(p);
}
}
VOID TEST(ProtocolJSONTest, Parse)
{
if (true) {