diff options
| author | Léo Lam <leo@leolam.fr> | 2021-06-02 03:38:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-02 03:38:01 +0200 |
| commit | 3ef9d5f6595f8ffac5d93314214aed735616f111 (patch) | |
| tree | b2b9a6284b925adeea3f3221791e1ca0d5273867 /Source/Core/Common/StringUtil.cpp | |
| parent | a12865570d7c0eacd77f1bed850772e5f8aea4d9 (diff) | |
| parent | 99ed43280dec1eec088bbf4242105c0953924e39 (diff) | |
Merge pull request #9749 from Dentomologist/escape_update_commit_descriptions
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; +} |
