Browse Source

Add DocumentData::setFileName.

pull/17122/head
John Preston 2 months ago
parent
commit
2b11e45692
  1. 40
      Telegram/SourceFiles/data/data_document.cpp
  2. 1
      Telegram/SourceFiles/data/data_document.h

40
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;

1
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();

Loading…
Cancel
Save