From eee252bb746299260d0740a686dee9bab488c1cc Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 22 Jan 2020 17:19:59 +0300 Subject: [PATCH] Filter out Unicode tag symbols from document names. Fixes #7005. --- .../view/media/history_view_document.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/history/view/media/history_view_document.cpp b/Telegram/SourceFiles/history/view/media/history_view_document.cpp index 122cf42eb..980c5dac2 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_document.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_document.cpp @@ -30,6 +30,35 @@ namespace { constexpr auto kAudioVoiceMsgUpdateView = crl::time(100); +[[nodiscard]] QString CleanTagSymbols(const QString &value) { + auto result = QString(); + const auto begin = value.begin(), end = value.end(); + auto from = begin; + for (auto ch = begin; ch != end; ++ch) { + if (ch->isHighSurrogate() + && (ch + 1) != end + && (ch + 1)->isLowSurrogate() + && QChar::surrogateToUcs4( + ch->unicode(), + (ch + 1)->unicode()) >= 0xe0000) { + if (ch > from) { + if (result.isEmpty()) { + result.reserve(value.size()); + } + result.append(from, ch - from); + } + ++ch; + from = ch + 1; + } + } + if (from == begin) { + return value; + } else if (end > from) { + result.append(from, end - from); + } + return result; +} + } // namespace Document::Document( @@ -104,7 +133,8 @@ void Document::createComponents(bool caption) { } void Document::fillNamedFromData(HistoryDocumentNamed *named) { - const auto nameString = named->_name = _data->composeNameString(); + const auto nameString = named->_name = CleanTagSymbols( + _data->composeNameString()); named->_namew = st::semiboldFont->width(nameString); }