diff --git a/Telegram/SourceFiles/core/file_utilities.cpp b/Telegram/SourceFiles/core/file_utilities.cpp index 3b0591df6..a90ee52b9 100644 --- a/Telegram/SourceFiles/core/file_utilities.cpp +++ b/Telegram/SourceFiles/core/file_utilities.cpp @@ -160,53 +160,6 @@ QString DefaultDownloadPath() { + '/'; } -QString NameFromUserString(QString name) { - static const auto Bad = { '/', '\\', '<', '>', ':', '"', '|', '?', '*' }; - for (auto &ch : name) { - if (ch < 32 || ranges::find(Bad, ch.unicode()) != end(Bad)) { - ch = '_'; - } - } - if (name.isEmpty() || name.endsWith(' ') || name.endsWith('.')) { - name.append('_'); - } -#ifdef Q_OS_WIN - static const auto BadNames = { - qstr("CON"), - qstr("PRN"), - qstr("AUX"), - qstr("NUL"), - qstr("COM1"), - qstr("COM2"), - qstr("COM3"), - qstr("COM4"), - qstr("COM5"), - qstr("COM6"), - qstr("COM7"), - qstr("COM8"), - qstr("COM9"), - qstr("LPT1"), - qstr("LPT2"), - qstr("LPT3"), - qstr("LPT4"), - qstr("LPT5"), - qstr("LPT6"), - qstr("LPT7"), - qstr("LPT8"), - qstr("LPT9") - }; - for (const auto bad : BadNames) { - if (name.startsWith(bad, Qt::CaseInsensitive)) { - if (name.size() == bad.size() || name[bad.size()] == '.') { - name = '_' + name; - break; - } - } - } -#endif // Q_OS_WIN - return name; -} - namespace internal { void UnsafeOpenEmailLinkDefault(const QString &email) { diff --git a/Telegram/SourceFiles/core/file_utilities.h b/Telegram/SourceFiles/core/file_utilities.h index 8d913f2a9..8e25f691e 100644 --- a/Telegram/SourceFiles/core/file_utilities.h +++ b/Telegram/SourceFiles/core/file_utilities.h @@ -37,8 +37,6 @@ void ShowInFolder(const QString &filepath); [[nodiscard]] QString DefaultDownloadPath(); -[[nodiscard]] QString NameFromUserString(QString name); - namespace internal { inline QString UrlToLocalDefault(const QUrl &url) { diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index a036b84b2..f23a484b0 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -30,6 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/image/image.h" #include "ui/image/image_source.h" #include "ui/text/text_utilities.h" +#include "base/base_file_utilities.h" #include "mainwindow.h" #include "core/application.h" #include "lottie/lottie_animation.h" @@ -136,13 +137,7 @@ QString FileNameUnsafe( QString name, bool savingAs, const QDir &dir) { -#ifdef Q_OS_WIN - name = name.replace(QRegularExpression(qsl("[\\\\\\/\\:\\*\\?\\\"\\<\\>\\|]")), qsl("_")); -#elif defined Q_OS_MAC - name = name.replace(QRegularExpression(qsl("[\\:]")), qsl("_")); -#elif defined Q_OS_LINUX - name = name.replace(QRegularExpression(qsl("[\\/]")), qsl("_")); -#endif + name = base::FileNameFromUserString(name); if (Global::AskDownloadPath() || savingAs) { if (!name.isEmpty() && name.at(0) == QChar::fromLatin1('.')) { name = filedialogDefaultName(prefix, name); diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index aab49845e..1b006d2df 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "export/export_settings.h" #include "export/output/export_output_file.h" +#include "base/base_file_utilities.h" #include "core/mime_type.h" #include "core/utils.h" #include @@ -337,53 +338,6 @@ QString ComputeDocumentName( } } -QString CleanDocumentName(QString 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 -#ifdef Q_OS_WIN - '\\', - '/', - ':', - '*', - '?', - '"', - '<', - '>', - '|', -#elif defined Q_OS_MAC // Q_OS_WIN - ':', -#elif defined Q_OS_LINUX // Q_OS_WIN || Q_OS_MAC - '/', -#endif // Q_OS_WIN || Q_OS_MAC || Q_OS_LINUX - }; - for (const auto ch : controls) { - name = std::move(name).replace(ch, '_'); - } - -#ifdef Q_OS_WIN - const auto lower = name.trimmed().toLower(); - const auto kBadExtensions = { qstr(".lnk"), qstr(".scf") }; - const auto kMaskExtension = qsl(".download"); - for (const auto extension : kBadExtensions) { - if (lower.endsWith(extension)) { - return name + kMaskExtension; - } - } -#endif // Q_OS_WIN - - return name; -} - QString DocumentFolder(const Document &data) { if (data.isVideoFile) { return "video_files"; @@ -469,7 +423,8 @@ Document ParseDocument( MTP_string()); result.file.suggestedPath = suggestedFolder + DocumentFolder(result) + '/' - + CleanDocumentName(ComputeDocumentName(context, result, date)); + + base::FileNameFromUserString( + ComputeDocumentName(context, result, date)); result.thumb = ParseDocumentThumb( data, diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 31d5af17f..06ecd901e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -28,6 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "lang/lang_keys.h" #include "base/event_filter.h" +#include "base/base_file_utilities.h" #include "base/zlib_help.h" #include "base/unixtime.h" #include "data/data_session.h" @@ -435,7 +436,7 @@ SendMediaReady PrepareThemeMedia( }; push("s", std::move(thumbnail)); - const auto filename = File::NameFromUserString(name) + const auto filename = base::FileNameFromUserString(name) + qsl(".tdesktop-theme"); auto attributes = QVector( 1, diff --git a/Telegram/lib_base b/Telegram/lib_base index dd5ca832f..2169055d7 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit dd5ca832f9b212e553ea5afee9a2dab2c3acd982 +Subproject commit 2169055d740dc069924e609fcc473006e5511134 diff --git a/Telegram/lib_ui b/Telegram/lib_ui index bc62f87f0..37f777e23 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit bc62f87f0ec7a0ef21ad4f676ef65cbb3d3631a4 +Subproject commit 37f777e230215aeba0ee6eba149cff7b64d7ed0d