Skip to content

Commit

Permalink
Merge pull request #16340 from hrydgard/html-fix-ampersands
Browse files Browse the repository at this point in the history
Fix parsing ampersands in server listings for streaming
  • Loading branch information
unknownbrackets committed Nov 5, 2022
2 parents 6f9ddd9 + 675a046 commit bbee15f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Common/StringUtils.cpp
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit bbee15f

Please sign in to comment.