From 2b11e456927418f06a6c8497e6821ac365e8fc0b Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 11 Oct 2021 21:46:29 +0400 Subject: [PATCH] Add DocumentData::setFileName. --- Telegram/SourceFiles/data/data_document.cpp | 40 +++++++++++---------- Telegram/SourceFiles/data/data_document.h | 1 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index a132650df7..4fe3f49bcb 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -373,24 +373,7 @@ void DocumentData::setattributes( } } }, [&](const MTPDdocumentAttributeFilename &data) { - _filename = qs(data.vfile_name()); - - // We don't want LTR/RTL mark/embedding/override/isolate chars - // in filenames, because they introduce a security issue, when - // an executable "Fil[x]gepj.exe" may look like "Filexe.jpeg". - QChar controls[] = { - 0x200E, // LTR Mark - 0x200F, // RTL Mark - 0x202A, // LTR Embedding - 0x202B, // RTL Embedding - 0x202D, // LTR Override - 0x202E, // RTL Override - 0x2066, // LTR Isolate - 0x2067, // RTL Isolate - }; - for (const auto &ch : controls) { - _filename = std::move(_filename).replace(ch, "_"); - } + setFileName(_filename); }, [&](const MTPDdocumentAttributeHasStickers &data) { _flags |= Flag::HasAttachedStickers; }); @@ -768,6 +751,27 @@ void DocumentData::setLoadedInMediaCache(bool loaded) { } } +void DocumentData::setFileName(const QString &remoteFileName) { + _filename = remoteFileName; + + // We don't want LTR/RTL mark/embedding/override/isolate chars + // in filenames, because they introduce a security issue, when + // an executable "Fil[x]gepj.exe" may look like "Filexe.jpeg". + QChar controls[] = { + 0x200E, // LTR Mark + 0x200F, // RTL Mark + 0x202A, // LTR Embedding + 0x202B, // RTL Embedding + 0x202D, // LTR Override + 0x202E, // RTL Override + 0x2066, // LTR Isolate + 0x2067, // RTL Isolate + }; + for (const auto &ch : controls) { + _filename = std::move(_filename).replace(ch, "_"); + } +} + void DocumentData::setLoadedInMediaCacheLocation() { _location = Core::FileLocation(); _flags |= Flag::LoadedInMediaCache; diff --git a/Telegram/SourceFiles/data/data_document.h b/Telegram/SourceFiles/data/data_document.h index 09d1f5b3c9..f2eeb688fa 100644 --- a/Telegram/SourceFiles/data/data_document.h +++ b/Telegram/SourceFiles/data/data_document.h @@ -296,6 +296,7 @@ private: void validateLottieSticker(); void setMaybeSupportsStreaming(bool supports); void setLoadedInMediaCacheLocation(); + void setFileName(const QString &remoteFileName); void finishLoad(); void handleLoaderUpdates();