Updater: Escape HTML characters in commit descriptions

This commit is contained in:
Dentomologist
2021-05-24 09:44:21 -07:00
parent a12865570d
commit 99ed43280d
4 changed files with 34 additions and 3 deletions

View File

@ -5,6 +5,7 @@
#include "Common/StringUtil.h"
#include <algorithm>
#include <array>
#include <codecvt>
#include <cstdarg>
#include <cstddef>
@ -664,3 +665,21 @@ std::vector<std::string> CommandLineToUtf8Argv(const wchar_t* command_line)
return argv;
}
#endif
std::string GetEscapedHtml(std::string html)
{
static constexpr std::array<std::array<const char*, 2>, 5> replacements{{
// Escape ampersand first to avoid escaping the ampersands in other replacements
{{"&", "&amp;"}},
{{"<", "&lt;"}},
{{">", "&gt;"}},
{{"\"", "&quot;"}},
{{"'", "&apos;"}},
}};
for (const auto& [unescaped, escaped] : replacements)
{
html = ReplaceAll(html, unescaped, escaped);
}
return html;
}