From 95580b5f11617e4dd7aa78fbd23dcde6ee6bf64a Mon Sep 17 00:00:00 2001 From: mcpiroman <38111589+mcpiroman@users.noreply.github.com> Date: Wed, 18 Sep 2019 00:43:24 +0200 Subject: [PATCH] Bugfix: Escape HTML entities (#2777) --- src/buffer/out/textBuffer.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/buffer/out/textBuffer.cpp b/src/buffer/out/textBuffer.cpp index eb18a815a7..1c51fde4bf 100644 --- a/src/buffer/out/textBuffer.cpp +++ b/src/buffer/out/textBuffer.cpp @@ -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; } };