Skip to content
Snippets Groups Projects
Commit cb20a75b authored by Sergey Linev's avatar Sergey Linev Committed by Bertrand Bellenot
Browse files

json: correctly process escape characters in the JSON string

parent bf91858c
No related branches found
No related tags found
No related merge requests found
......@@ -144,10 +144,25 @@ void TRootSnifferStoreJson::SetField(Int_t lvl, const char *field,
fBuf->Append(",");
if (!fCompact) fBuf->Append("\n");
fBuf->Append(TString::Format("%*s\"%s\"%s", fCompact ? 0 : lvl * 4 + 2, "", field, (fCompact ? ":" : " : ")));
if (with_quotes) {
fBuf->Append(TString::Format("\"%s\"", value));
} else {
if (!with_quotes) {
fBuf->Append(value);
} else {
fBuf->Append("\"");
for (const char *v = value; *v != 0; v++) {
switch (*v) {
case '\n':
fBuf->Append("\\\\n");
break;
case '\t':
fBuf->Append("\\\\t");
break;
default:
fBuf->Append(*v);
// double escape character, only keep \' and \" sequences untouched
if ((*v == '\\') && (*(v+1) != '\'') && (*(v+1) != '\"')) fBuf->Append("\\");
}
}
fBuf->Append("\"");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment