Skip to content

Commit

Permalink
Revert "Check for local URLs more strictly."
Browse files Browse the repository at this point in the history
This reverts commit c3fda41.
  • Loading branch information
john-preston committed Sep 10, 2024
1 parent ca3c179 commit d1e3b9f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 36 deletions.
3 changes: 1 addition & 2 deletions Telegram/SourceFiles/boxes/send_files_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ For license and copyright information please follow this link:
#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"
Expand Down Expand Up @@ -72,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, Core::UrlIsLocal);
return !urls.isEmpty() && ranges::all_of(urls, &QUrl::isLocalFile);
}

[[nodiscard]] bool CanAddFiles(not_null<const QMimeData*> data) {
Expand Down
6 changes: 1 addition & 5 deletions Telegram/SourceFiles/core/file_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ For license and copyright information please follow this link:
*/
#pragma once

namespace Core {
bool UrlIsLocal(const QUrl &url);
} // namespace Core

namespace Main {
class Session;
} // namespace Main
Expand Down Expand Up @@ -49,7 +45,7 @@ void ShowInFolder(const QString &filepath);
namespace internal {

inline QString UrlToLocalDefault(const QUrl &url) {
return Core::UrlIsLocal(url) ? url.toLocalFile() : QString();
return url.toLocalFile();
}

void UnsafeOpenUrlDefault(const QString &url);
Expand Down
13 changes: 1 addition & 12 deletions Telegram/SourceFiles/core/mime_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,13 @@ 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, UrlIsLocal)) {
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
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, ".\\/");
Expand Down
1 change: 0 additions & 1 deletion Telegram/SourceFiles/core/mime_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ 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,
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5786,7 +5786,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, Core::UrlIsLocal)) {
if (ranges::all_of(urls, &QUrl::isLocalFile)) {
return true;
}
}
Expand Down
4 changes: 0 additions & 4 deletions Telegram/SourceFiles/platform/mac/file_utilities_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#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"

Expand Down Expand Up @@ -380,9 +379,6 @@ - (void) dealloc {
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];
Expand Down
23 changes: 12 additions & 11 deletions Telegram/SourceFiles/storage/storage_media_prepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ bool ValidatePhotoEditorMediaDragData(not_null<const QMimeData*> data) {
}

if (!urls.isEmpty()) {
using namespace Core;
const auto file = Platform::File::UrlToLocal(urls.front());
if (!file.isEmpty()) {
const auto url = urls.front();
if (url.isLocalFile()) {
using namespace Core;
const auto file = Platform::File::UrlToLocal(url);
const auto info = QFileInfo(file);
return FileIsImage(file, MimeTypeForFile(info).name())
&& QImageReader(file).canRead();
Expand All @@ -106,10 +107,10 @@ bool ValidateEditMediaDragData(
}

if (albumType == Ui::AlbumType::PhotoVideo && !urls.isEmpty()) {
using namespace Core;
const auto file = Platform::File::UrlToLocal(urls.front());
if (!file.isEmpty()) {
const auto info = QFileInfo(file);
const auto url = urls.front();
if (url.isLocalFile()) {
using namespace Core;
const auto info = QFileInfo(Platform::File::UrlToLocal(url));
return IsMimeAcceptedForPhotoVideoAlbum(MimeTypeForFile(info).name());
}
}
Expand All @@ -133,10 +134,10 @@ MimeDataState ComputeMimeDataState(const QMimeData *data) {

auto allAreSmallImages = true;
for (const auto &url : urls) {
const auto file = Platform::File::UrlToLocal(url);
if (file.isEmpty()) {
if (!url.isLocalFile()) {
return MimeDataState::None;
}
const auto file = Platform::File::UrlToLocal(url);

const auto info = QFileInfo(file);
if (info.isDir()) {
Expand Down Expand Up @@ -174,13 +175,13 @@ PreparedList PrepareMediaList(
auto locals = QStringList();
locals.reserve(files.size());
for (const auto &url : files) {
locals.push_back(Platform::File::UrlToLocal(url));
if (locals.back().isEmpty()) {
if (!url.isLocalFile()) {
return {
PreparedList::Error::NonLocalUrl,
url.toDisplayString()
};
}
locals.push_back(Platform::File::UrlToLocal(url));
}
return PrepareMediaList(locals, previewWidth, premium);
}
Expand Down

0 comments on commit d1e3b9f

Please sign in to comment.