2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Check for local URLs more strictly.

This commit is contained in:
John Preston
2024-08-20 17:21:11 +02:00
parent a4017e930e
commit c3fda41224
7 changed files with 36 additions and 16 deletions

View File

@@ -7,6 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Core {
bool UrlIsLocal(const QUrl &url);
} // namespace Core
namespace Main {
class Session;
} // namespace Main
@@ -45,7 +49,7 @@ void ShowInFolder(const QString &filepath);
namespace internal {
inline QString UrlToLocalDefault(const QUrl &url) {
return url.toLocalFile();
return Core::UrlIsLocal(url) ? url.toLocalFile() : QString();
}
void UnsafeOpenUrlDefault(const QString &url);

View File

@@ -226,13 +226,24 @@ bool CanSendFiles(not_null<const QMimeData*> data) {
if (data->hasImage()) {
return true;
} else if (const auto urls = ReadMimeUrls(data); !urls.empty()) {
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
if (ranges::all_of(urls, UrlIsLocal)) {
return true;
}
}
return false;
}
bool UrlIsLocal(const QUrl &url) {
if (!url.isLocalFile()) {
return false;
}
const auto result = url.toLocalFile();
if (result.startsWith("//")) {
return false;
}
return !result.isEmpty();
}
QString FileExtension(const QString &filepath) {
const auto reversed = ranges::views::reverse(filepath);
const auto last = ranges::find_first_of(reversed, ".\\/");

View File

@@ -68,6 +68,7 @@ struct MimeImageData {
[[nodiscard]] QString ReadMimeText(not_null<const QMimeData*> data);
[[nodiscard]] QList<QUrl> ReadMimeUrls(not_null<const QMimeData*> data);
[[nodiscard]] bool CanSendFiles(not_null<const QMimeData*> data);
[[nodiscard]] bool UrlIsLocal(const QUrl &url);
enum class NameType : uchar {
Unknown,