Skip to content

Commit

Permalink
escape file path using rapidJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Aug 17, 2023
1 parent bceb391 commit 5968324
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions benchmark/utils/general_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::stringstream>(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<rapidjson::StringBuffer> writer(sb);
d.Accept(writer);
input_stream = std::make_unique<std::stringstream>(sb.GetString());
}
}

Expand Down

0 comments on commit 5968324

Please sign in to comment.