properly escape json names (#652)

This commit is contained in:
BaaMeow 2018-08-16 12:47:09 -04:00 committed by Dominic Hamon
parent 94c4d6d5c6
commit af441fc114
2 changed files with 8 additions and 2 deletions

View File

@ -78,7 +78,12 @@ bool JSONReporter::ReportContext(const Context& context) {
out << indent << FormatKV("date", walltime_value) << ",\n";
if (Context::executable_name) {
out << indent << FormatKV("executable", Context::executable_name) << ",\n";
// windows uses backslash for its path separator,
// which must be escaped in JSON otherwise it blows up conforming JSON
// decoders
std::string executable_name = Context::executable_name;
ReplaceAll(&executable_name, "\\", "\\\\");
out << indent << FormatKV("executable", executable_name) << ",\n";
}
CPUInfo const& info = context.cpu_info;

View File

@ -23,7 +23,8 @@ static int AddContextCases() {
{{"^\\{", MR_Default},
{"\"context\":", MR_Next},
{"\"date\": \"", MR_Next},
{"\"executable\": \".*/reporter_output_test(\\.exe)?\",", MR_Next},
{"\"executable\": \".*(/|\\\\)reporter_output_test(\\.exe)?\",",
MR_Next},
{"\"num_cpus\": %int,$", MR_Next},
{"\"mhz_per_cpu\": %float,$", MR_Next},
{"\"cpu_scaling_enabled\": ", MR_Next},