Bugfix: Escape HTML entities (#2777)

This commit is contained in:
mcpiroman
2019-09-18 00:43:24 +02:00
committed by Carlos Zamora
parent 7edbbd1ccb
commit 95580b5f11

View File

@@ -1148,9 +1148,25 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows, const int fontHeightPo
const auto writeAccumulatedChars = [&](bool includeCurrent) {
if (col > startOffset)
{
// note: this should be escaped (for '<', '>', and '&'),
// however MS Word doesn't appear to support HTML entities
htmlBuilder << ConvertToA(CP_UTF8, std::wstring_view(rows.text.at(row)).substr(startOffset, col - startOffset + includeCurrent));
const auto unescapedText = ConvertToA(CP_UTF8, std::wstring_view(rows.text.at(row)).substr(startOffset, col - startOffset + includeCurrent));
for (const auto c : unescapedText)
{
switch (c)
{
case '<':
htmlBuilder << "&lt;";
break;
case '>':
htmlBuilder << "&gt;";
break;
case '&':
htmlBuilder << "&amp;";
break;
default:
htmlBuilder << c;
}
}
startOffset = col;
}
};