Better tg:// URL formatting.

GitOrigin-RevId: 766363c58886800c186bceabc8ce4746f1835bf6
This commit is contained in:
levlam 2018-06-19 17:02:55 +03:00
parent 1ef5c89a91
commit 1f9052f85b

View File

@ -288,13 +288,17 @@ Result<string> check_url(MutableSlice url) {
} }
TRY_RESULT(http_url, parse_url(url)); TRY_RESULT(http_url, parse_url(url));
if (is_tg) { 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"); return Status::Error("Wrong tg URL");
} }
auto result = http_url.get_url(); Slice query(http_url.query_);
CHECK(begins_with(result, "http://")); CHECK(query[0] == '/');
return PSTRING() << "tg" << Slice(result).substr(4); if (query[1] == '?') {
query.remove_prefix(1);
}
return PSTRING() << "tg://" << http_url.host_ << query;
} }
if (url.find('.') == string::npos) { if (url.find('.') == string::npos) {