From 6ee4682271b65f46b7df8cfc72058d856fadc7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Sch=C3=B6nleber?= Date: Tue, 14 Nov 2023 19:08:54 +0100 Subject: [PATCH 1/2] logging: improve escaping in yaml output --- common/common.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/common/common.cpp b/common/common.cpp index 6a711420004b4..692a42d01a185 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1188,6 +1188,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("\\\\[^n\"]"), "\\$&"); data_str = "\"" + data_str + "\""; fprintf(stream, "%s: %s\n", prop_name, data_str.c_str()); return; From fdbef3b4cc66a949bf226e654cc6f6a2fcdd5a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Sch=C3=B6nleber?= Date: Wed, 15 Nov 2023 08:54:15 +0100 Subject: [PATCH 2/2] logging: include review feedback --- common/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/common.cpp b/common/common.cpp index 692a42d01a185..6a98cb181039b 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -1188,7 +1188,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("\\\\[^n\"]"), "\\$&"); + 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;