1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

JSON: Filter string filed with special char

This commit is contained in:
winlin 2020-07-14 19:51:06 +08:00
parent dc8a63fb3c
commit 426938cc8a

View file

@ -1572,11 +1572,25 @@ SrsJsonArray* SrsJsonAny::to_array()
return p; return p;
} }
string escape(string v)
{
stringstream ss;
for (int i = 0; i < v.length(); i++) {
if (v.at(i) == '"') {
ss << '\\';
}
ss << v.at(i);
}
return ss.str();
}
string SrsJsonAny::dumps() string SrsJsonAny::dumps()
{ {
switch (marker) { switch (marker) {
case SRS_JSON_String: { case SRS_JSON_String: {
return "\"" + to_str() + "\""; return "\"" + escape(to_str()) + "\"";
} }
case SRS_JSON_Boolean: { case SRS_JSON_Boolean: {
return to_boolean()? "true" : "false"; return to_boolean()? "true" : "false";