Remove some more symbols from filenames.

This commit is contained in:
John Preston 2018-02-15 15:34:38 +03:00
parent 0f775e1e66
commit bc171f625a
1 changed files with 18 additions and 7 deletions

View File

@ -432,15 +432,26 @@ void DocumentData::setattributes(const QVector<MTPDocumentAttribute> &attributes
} }
} break; } break;
case mtpc_documentAttributeFilename: { case mtpc_documentAttributeFilename: {
auto &attribute = attributes[i]; const auto &attribute = attributes[i];
auto remoteFileName = qs( _filename = qs(
attribute.c_documentAttributeFilename().vfile_name); attribute.c_documentAttributeFilename().vfile_name);
// We don't want RTL Override characters in filenames, // We don't want LTR/RTL mark/embedding/override/isolate chars
// because they introduce a security issue, when a filename // in filenames, because they introduce a security issue, when
// "Fil[RTLO]gepj.exe" looks like "Filexe.jpeg" being ".exe" // an executable "Fil[x]gepj.exe" may look like "Filexe.jpeg".
auto rtlOverride = QChar(0x202E); QChar controls[] = {
_filename = std::move(remoteFileName).replace(rtlOverride, ""); 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, "_");
}
} break; } break;
} }
} }