From: Jannis Schönleber Date: Fri, 17 Nov 2023 15:24:07 +0000 (+0100) Subject: common : improve yaml log escaping (#4080) X-Git-Tag: upstream/0.0.4488~2958 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=9e87ef60e18d69338c5efea314aa7e718bf2040a;p=pkg%2Fggml%2Fsources%2Fllama.cpp common : improve yaml log escaping (#4080) * logging: improve escaping in yaml output * logging: include review feedback --- diff --git a/common/common.cpp b/common/common.cpp index e119317d..7ee29f5b 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -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;