]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
common : improve yaml log escaping (#4080)
authorJannis Schönleber <redacted>
Fri, 17 Nov 2023 15:24:07 +0000 (16:24 +0100)
committerGitHub <redacted>
Fri, 17 Nov 2023 15:24:07 +0000 (17:24 +0200)
* logging: improve escaping in yaml output

* logging: include review feedback

common/common.cpp

index e119317d6097ea0345e8b7576e00fd6b2db43118..7ee29f5ba492333d41e1656fa864954fa3fb2f3c 100644 (file)
@@ -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;