mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-24 17:26:58 +00:00
Check for local URLs more strictly.
This commit is contained in:
parent
a4017e930e
commit
c3fda41224
@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/premium_limits_box.h"
|
||||
#include "boxes/premium_preview_box.h"
|
||||
#include "boxes/send_credits_box.h"
|
||||
#include "platform/platform_file_utilities.h"
|
||||
#include "ui/effects/scroll_content_shadow.h"
|
||||
#include "ui/widgets/fields/number_input.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
@ -70,7 +71,7 @@ constexpr auto kMaxMessageLength = 4096;
|
||||
using Ui::SendFilesWay;
|
||||
|
||||
[[nodiscard]] inline bool CanAddUrls(const QList<QUrl> &urls) {
|
||||
return !urls.isEmpty() && ranges::all_of(urls, &QUrl::isLocalFile);
|
||||
return !urls.isEmpty() && ranges::all_of(urls, Core::UrlIsLocal);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool CanAddFiles(not_null<const QMimeData*> data) {
|
||||
|
@ -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);
|
||||
|
@ -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, ".\\/");
|
||||
|
@ -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,
|
||||
|
@ -5769,7 +5769,7 @@ bool HistoryWidget::canSendFiles(not_null<const QMimeData*> data) const {
|
||||
} else if (data->hasImage()) {
|
||||
return true;
|
||||
} else if (const auto urls = Core::ReadMimeUrls(data); !urls.empty()) {
|
||||
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
|
||||
if (ranges::all_of(urls, Core::UrlIsLocal)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "platform/mac/file_utilities_mac.h"
|
||||
|
||||
#include "base/platform/mac/base_utilities_mac.h"
|
||||
#include "core/mime_type.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "styles/style_window.h"
|
||||
|
||||
@ -379,6 +380,9 @@ namespace Platform {
|
||||
namespace File {
|
||||
|
||||
QString UrlToLocal(const QUrl &url) {
|
||||
if (!Core::UrlIsLocal(url)) {
|
||||
return QString();
|
||||
}
|
||||
auto result = url.toLocalFile();
|
||||
if (result.startsWith(u"/.file/id="_q)) {
|
||||
NSString *nsurl = [[[NSURL URLWithString: [NSString stringWithUTF8String: (u"file://"_q + result).toUtf8().constData()]] filePathURL] path];
|
||||
|
@ -83,10 +83,9 @@ bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
|
||||
}
|
||||
|
||||
if (!urls.isEmpty()) {
|
||||
const auto url = urls.front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto file = Platform::File::UrlToLocal(url);
|
||||
using namespace Core;
|
||||
const auto file = Platform::File::UrlToLocal(urls.front());
|
||||
if (!file.isEmpty()) {
|
||||
const auto info = QFileInfo(file);
|
||||
return FileIsImage(file, MimeTypeForFile(info).name())
|
||||
&& QImageReader(file).canRead();
|
||||
@ -107,10 +106,10 @@ bool ValidateEditMediaDragData(
|
||||
}
|
||||
|
||||
if (albumType == Ui::AlbumType::PhotoVideo && !urls.isEmpty()) {
|
||||
const auto url = urls.front();
|
||||
if (url.isLocalFile()) {
|
||||
using namespace Core;
|
||||
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
|
||||
using namespace Core;
|
||||
const auto file = Platform::File::UrlToLocal(urls.front());
|
||||
if (!file.isEmpty()) {
|
||||
const auto info = QFileInfo(file);
|
||||
return IsMimeAcceptedForPhotoVideoAlbum(MimeTypeForFile(info).name());
|
||||
}
|
||||
}
|
||||
@ -134,10 +133,10 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {
|
||||
|
||||
auto allAreSmallImages = true;
|
||||
for (const auto &url : urls) {
|
||||
if (!url.isLocalFile()) {
|
||||
const auto file = Platform::File::UrlToLocal(url);
|
||||
if (file.isEmpty()) {
|
||||
return MimeDataState::None;
|
||||
}
|
||||
const auto file = Platform::File::UrlToLocal(url);
|
||||
|
||||
const auto info = QFileInfo(file);
|
||||
if (info.isDir()) {
|
||||
@ -171,13 +170,13 @@ PreparedList PrepareMediaList(
|
||||
auto locals = QStringList();
|
||||
locals.reserve(files.size());
|
||||
for (const auto &url : files) {
|
||||
if (!url.isLocalFile()) {
|
||||
locals.push_back(Platform::File::UrlToLocal(url));
|
||||
if (locals.back().isEmpty()) {
|
||||
return {
|
||||
PreparedList::Error::NonLocalUrl,
|
||||
url.toDisplayString()
|
||||
};
|
||||
}
|
||||
locals.push_back(Platform::File::UrlToLocal(url));
|
||||
}
|
||||
return PrepareMediaList(locals, previewWidth, premium);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user