Fix parsing ampersands in server listings for streaming

Fixes #16263 , or so I hope - haven't actually tested it, but seems
straightforward enough.
This commit is contained in:
Henrik Rydgård 2022-11-05 23:31:30 +01:00
parent 10c6232b9b
commit 675a046759

View file

@ -286,6 +286,25 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
}
}
static std::string ApplyHtmlEscapes(std::string str) {
struct Repl {
const char *a;
const char *b;
};
static const Repl replacements[] = {
{ "&amp;", "&" },
// Easy to add more cases.
};
for (const Repl &r : replacements) {
str = ReplaceAll(str, r.a, r.b);
}
return str;
}
// Meant for HTML listings and similar, so supports some HTML escapes.
void GetQuotedStrings(const std::string& str, std::vector<std::string>& output)
{
size_t next = 0;
@ -294,7 +313,7 @@ void GetQuotedStrings(const std::string& str, std::vector<std::string>& output)
if (str[pos] == '\"' || str[pos] == '\'') {
if (even) {
//quoted text
output.emplace_back(str.substr(next, pos - next));
output.emplace_back(ApplyHtmlEscapes(str.substr(next, pos - next)));
even = 0;
} else {
//non quoted text