diff options
| author | Dentomologist <dentomologist@gmail.com> | 2021-05-24 09:44:21 -0700 |
|---|---|---|
| committer | Dentomologist <dentomologist@gmail.com> | 2021-06-01 17:22:19 -0700 |
| commit | 99ed43280dec1eec088bbf4242105c0953924e39 (patch) | |
| tree | b2b9a6284b925adeea3f3221791e1ca0d5273867 /Source/Core/Common/StringUtil.cpp | |
| parent | a12865570d7c0eacd77f1bed850772e5f8aea4d9 (diff) | |
Updater: Escape HTML characters in commit descriptions
Diffstat (limited to 'Source/Core/Common/StringUtil.cpp')
| -rw-r--r-- | Source/Core/Common/StringUtil.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
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 <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 + {{"&", "&"}}, + {{"<", "<"}}, + {{">", ">"}}, + {{"\"", """}}, + {{"'", "'"}}, + }}; + + for (const auto& [unescaped, escaped] : replacements) + { + html = ReplaceAll(html, unescaped, escaped); + } + return html; +} |
