From 1f9052f85b4dd3fea02dd49e648a47977e2bebfa Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 19 Jun 2018 17:02:55 +0300 Subject: [PATCH] Better tg:// URL formatting. GitOrigin-RevId: 766363c58886800c186bceabc8ce4746f1835bf6 --- td/telegram/misc.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/td/telegram/misc.cpp b/td/telegram/misc.cpp index 59cd77ca..d1ee5342 100644 --- a/td/telegram/misc.cpp +++ b/td/telegram/misc.cpp @@ -288,13 +288,17 @@ Result check_url(MutableSlice url) { } TRY_RESULT(http_url, parse_url(url)); if (is_tg) { - if (begins_with(url, "http://") || http_url.protocol_ == HttpUrl::Protocol::HTTPS || !http_url.userinfo_.empty() || http_url.specified_port_ != 0 || http_url.is_ipv6_) { + if (begins_with(url, "http://") || http_url.protocol_ == HttpUrl::Protocol::HTTPS || !http_url.userinfo_.empty() || + http_url.specified_port_ != 0 || http_url.is_ipv6_) { return Status::Error("Wrong tg URL"); } - auto result = http_url.get_url(); - CHECK(begins_with(result, "http://")); - return PSTRING() << "tg" << Slice(result).substr(4); + Slice query(http_url.query_); + CHECK(query[0] == '/'); + if (query[1] == '?') { + query.remove_prefix(1); + } + return PSTRING() << "tg://" << http_url.host_ << query; } if (url.find('.') == string::npos) {