From 187c2dda201e7259c7a516581b38f00f0b516aae Mon Sep 17 00:00:00 2001 From: xmdn <72883689+xmdnx@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:54:16 +0300 Subject: [PATCH] Check more protocols while adding link (#28407) --- .../SourceFiles/chat_helpers/message_field.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 378175969..4485a94d0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -63,6 +63,12 @@ constexpr auto kParseLinksTimeout = crl::time(1000); constexpr auto kTypesDuration = 4 * crl::time(1000); constexpr auto kCodeLanguageLimit = 32; +constexpr auto kLinkProtocols = { + "http://", + "https://", + "tonsite://" +}; + // For mention / custom emoji tags save and validate selfId, // ignore tags for different users. [[nodiscard]] Fn FieldTagMimeProcessor( @@ -152,11 +158,10 @@ void EditLinkBox( return startLink.trimmed(); } const auto clipboard = QGuiApplication::clipboard()->text().trimmed(); - if (clipboard.startsWith("http://") - || clipboard.startsWith("https://")) { - return clipboard; - } - return QString(); + const auto starts = [&](const auto &protocol) { + return clipboard.startsWith(protocol); + }; + return std::ranges::any_of(kLinkProtocols, starts) ? clipboard : QString(); }(); const auto url = Ui::AttachParentChild( content,