Skip to content

Commit

Permalink
common : improve yaml log escaping (ggerganov#4080)
Browse files Browse the repository at this point in the history
* logging: improve escaping in yaml output

* logging: include review feedback
  • Loading branch information
joennlae authored and olexiyb committed Nov 23, 2023
1 parent 85a81ff commit 38c6ef1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ void dump_string_yaml_multiline(FILE * stream, const char * prop_name, const cha
if (!data_str.empty() && (std::isspace(data_str[0]) || std::isspace(data_str.back()))) {
data_str = std::regex_replace(data_str, std::regex("\n"), "\\n");
data_str = std::regex_replace(data_str, std::regex("\""), "\\\"");
data_str = std::regex_replace(data_str, std::regex(R"(\\[^n"])"), R"(\$&)");
data_str = "\"" + data_str + "\"";
fprintf(stream, "%s: %s\n", prop_name, data_str.c_str());
return;
Expand Down

0 comments on commit 38c6ef1

Please sign in to comment.