mirror of
https://github.com/microsoft/terminal.git
synced 2026-05-06 12:01:06 -04:00
Bugfix: Escape HTML entities (#2777)
This commit is contained in:
@@ -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 << "<";
|
||||
break;
|
||||
case '>':
|
||||
htmlBuilder << ">";
|
||||
break;
|
||||
case '&':
|
||||
htmlBuilder << "&";
|
||||
break;
|
||||
default:
|
||||
htmlBuilder << c;
|
||||
}
|
||||
}
|
||||
|
||||
startOffset = col;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user