Add DocumentData::setFileName.

This commit is contained in:
John Preston 2021-10-11 21:46:29 +04:00
parent 6163e922b3
commit 2b11e45692
2 changed files with 23 additions and 18 deletions

View File

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

View File

@ -296,6 +296,7 @@ private:
void validateLottieSticker();
void setMaybeSupportsStreaming(bool supports);
void setLoadedInMediaCacheLocation();
void setFileName(const QString &remoteFileName);
void finishLoad();
void handleLoaderUpdates();