From 1a901a0e39def4b22f25ef5c4c99f0b79c159d71 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 17 Aug 2024 20:07:34 +0300 Subject: [PATCH] Fix tonsite links. --- td/telegram/LinkManager.cpp | 2 +- td/telegram/MessageEntity.cpp | 4 ++-- test/link.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index ca3fc2bd4..737552304 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -1203,7 +1203,7 @@ Result LinkManager::check_link_impl(Slice link, bool http_only, bool htt query.remove_prefix(1); } for (auto c : http_url.host_) { - if (!is_alnum(c) && c != '-' && c != '_') { + if (!is_alnum(c) && c != '-' && c != '_' && !(is_tonsite && c == '.')) { return Status::Error("Unallowed characters in URL host"); } } diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index 7bfcffd80..1cb9e0d77 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -649,8 +649,8 @@ static vector match_tg_urls(Slice str) { } else if (ptr - begin >= 3 && to_lower(ptr[-3]) == 't' && to_lower(ptr[-2]) == 'o' && to_lower(ptr[-1]) == 'n') { url_begin = ptr - 3; } else if (ptr - begin >= 7 && to_lower(ptr[-7]) == 't' && to_lower(ptr[-6]) == 'o' && to_lower(ptr[-5]) == 'n' && - to_lower(ptr[-5]) == 's' && to_lower(ptr[-5]) == 'i' && to_lower(ptr[-5]) == 't' && - to_lower(ptr[-5]) == 'e') { + to_lower(ptr[-4]) == 's' && to_lower(ptr[-3]) == 'i' && to_lower(ptr[-2]) == 't' && + to_lower(ptr[-1]) == 'e') { url_begin = ptr - 3; } } diff --git a/test/link.cpp b/test/link.cpp index 4225a2379..6403b9896 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -80,6 +80,7 @@ TEST(Link, check_link) { check_link("..", "http://../"); check_link("https://.", ""); check_link("tOnSiTe://google", "tonsite://google/"); + check_link("tOnSiTe://google.ton?t=1#we", "tonsite://google.ton?t=1#we"); } static td::td_api::object_ptr get_internal_link_type_object(