diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 85c31fcd6..83a02cf7d 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -945,6 +945,16 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) { return result; } } + + if (http_url.query_.size() > 1) { + for (auto telegraph_url : {Slice("telegra.ph"), Slice("te.legra.ph"), Slice("graph.org")}) { + if (host == telegraph_url) { + result.type_ = LinkType::Telegraph; + result.query_ = std::move(http_url.query_); + return result; + } + } + } } return result; } @@ -963,6 +973,8 @@ unique_ptr LinkManager::parse_internal_link(Slice lin return parse_tg_link_query(info.query_, is_trusted); case LinkType::TMe: return parse_t_me_link_query(info.query_, is_trusted); + case LinkType::Telegraph: + return td::make_unique(PSTRING() << "https://telegra.ph" << info.query_); default: UNREACHABLE(); return nullptr; diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index ccf423ffa..bcd284bb3 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -123,7 +123,7 @@ class LinkManager final : public Actor { class InternalLinkUserPhoneNumber; class InternalLinkVoiceChat; - enum class LinkType : int32 { External, TMe, Tg }; + enum class LinkType : int32 { External, TMe, Tg, Telegraph }; struct LinkInfo { LinkType type_ = LinkType::External; diff --git a/test/link.cpp b/test/link.cpp index 991b3b9c8..256c57bf8 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -27,7 +27,8 @@ static void check_find_urls(const td::string &url, bool is_valid) { { if (is_valid && (td::begins_with(url_lower, "http") || td::begins_with(url_lower, "t.me")) && - url.find('.') != td::string::npos && url.find(' ') == td::string::npos && url != "http://..") { + url.find('.') != td::string::npos && url.find(' ') == td::string::npos && url != "http://.." && + url.find("ra.ph") == td::string::npos && url.find("Aph") == td::string::npos) { auto urls = td::find_urls(url); ASSERT_EQ(1u, urls.size()); ASSERT_STREQ(url, urls[0].first); @@ -86,7 +87,7 @@ static void parse_internal_link(const td::string &url, td::td_api::object_ptrget_id() == td::td_api::internalLinkTypeMessageDraft::ID) { static_cast(object.get())->text_->entities_.clear(); } - ASSERT_STREQ(url + " " + to_string(expected), url + " " + to_string(object)); + ASSERT_STREQ(url + ' ' + to_string(expected), url + ' ' + to_string(object)); } else { LOG_IF(ERROR, expected != nullptr) << url; ASSERT_TRUE(expected == nullptr); @@ -964,4 +965,10 @@ TEST(Link, parse_internal_link) { parse_internal_link("setlanguage.t.me", nullptr); parse_internal_link("share.t.me", nullptr); parse_internal_link("socks.t.me", nullptr); + + parse_internal_link("www.telegra.ph/", nullptr); + parse_internal_link("www.telegrA.ph/#", nullptr); + parse_internal_link("www.telegrA.ph/?", instant_view("https://telegra.ph/?")); + parse_internal_link("http://te.leGra.ph/?", instant_view("https://telegra.ph/?")); + parse_internal_link("https://grAph.org/12345", instant_view("https://telegra.ph/12345")); }