diff --git a/src/json_reporter.cc b/src/json_reporter.cc index 6d0706f1..127a96a0 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -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; diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc index 1662fcb8..80f3e786 100644 --- a/test/reporter_output_test.cc +++ b/test/reporter_output_test.cc @@ -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},