diff --git a/benchmark/utils/general_matrix.hpp b/benchmark/utils/general_matrix.hpp index e499d5d9326..2049dadf45f 100644 --- a/benchmark/utils/general_matrix.hpp +++ b/benchmark/utils/general_matrix.hpp @@ -67,9 +67,17 @@ void initialize_argument_parsing_matrix( << "-input and -input_matrix cannot be used simultaneously\n"; std::exit(1); } - auto input_json = R"([{"filename":")" + input_matrix_str + "\"" + - additional_matrix_file_json + "}]"; - input_stream = std::make_unique(input_json); + // create JSON for the filename via RapidJSON to ensure the string is + // correctly escaped + rapidjson::Document d; + auto json_template = + R"([{"filename":"")" + additional_matrix_file_json + "}]"; + d.Parse(json_template.c_str()); + d[0]["filename"].SetString(input_matrix_str.c_str(), d.GetAllocator()); + rapidjson::StringBuffer sb; + rapidjson::PrettyWriter writer(sb); + d.Accept(writer); + input_stream = std::make_unique(sb.GetString()); } }