From 99ed43280dec1eec088bbf4242105c0953924e39 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Mon, 24 May 2021 09:44:21 -0700 Subject: Updater: Escape HTML characters in commit descriptions --- Source/Core/Common/StringUtil.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'Source/Core/Common/StringUtil.cpp') diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 9c57bf944a..77fcd731a1 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -5,6 +5,7 @@ #include "Common/StringUtil.h" #include +#include #include #include #include @@ -664,3 +665,21 @@ std::vector CommandLineToUtf8Argv(const wchar_t* command_line) return argv; } #endif + +std::string GetEscapedHtml(std::string html) +{ + static constexpr std::array, 5> replacements{{ + // Escape ampersand first to avoid escaping the ampersands in other replacements + {{"&", "&"}}, + {{"<", "<"}}, + {{">", ">"}}, + {{"\"", """}}, + {{"'", "'"}}, + }}; + + for (const auto& [unescaped, escaped] : replacements) + { + html = ReplaceAll(html, unescaped, escaped); + } + return html; +} -- cgit v1.2.3