Pass Slice to parse_url.

GitOrigin-RevId: e6cd357042b827ca56a11bb377c8b07ccd120230
This commit is contained in:
levlam 2019-08-05 12:56:28 +03:00
parent 84b33cd6a8
commit ad167a48ba
9 changed files with 10 additions and 15 deletions

View File

@ -1072,7 +1072,7 @@ string InlineQueriesManager::get_web_document_url(const tl_object_ptr<telegram_a
return {}; return {};
} }
string url; Slice url;
switch (web_document_ptr->get_id()) { switch (web_document_ptr->get_id()) {
case telegram_api::webDocument::ID: { case telegram_api::webDocument::ID: {
auto web_document = static_cast<const telegram_api::webDocument *>(web_document_ptr.get()); auto web_document = static_cast<const telegram_api::webDocument *>(web_document_ptr.get());

View File

@ -1872,8 +1872,7 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
break; break;
} }
case telegram_api::messageEntityTextUrl::ID: { case telegram_api::messageEntityTextUrl::ID: {
// TODO const telegram_api::messageEntityTextUrl * auto entity_text_url = static_cast<const telegram_api::messageEntityTextUrl *>(entity.get());
auto entity_text_url = static_cast<telegram_api::messageEntityTextUrl *>(entity.get());
auto r_url = check_url(entity_text_url->url_); auto r_url = check_url(entity_text_url->url_);
if (r_url.is_error()) { if (r_url.is_error()) {
LOG(ERROR) << "Wrong URL entity: \"" << entity_text_url->url_ << "\": " << r_url.error().message() << " from " LOG(ERROR) << "Wrong URL entity: \"" << entity_text_url->url_ << "\": " << r_url.error().message() << " from "

View File

@ -380,7 +380,7 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
switch (button_type_id) { switch (button_type_id) {
case td_api::inlineKeyboardButtonTypeUrl::ID: { case td_api::inlineKeyboardButtonTypeUrl::ID: {
current_button.type = InlineKeyboardButton::Type::Url; current_button.type = InlineKeyboardButton::Type::Url;
TRY_RESULT(url, check_url(static_cast<td_api::inlineKeyboardButtonTypeUrl *>(button->type_.get())->url_)); TRY_RESULT(url, check_url(static_cast<const td_api::inlineKeyboardButtonTypeUrl *>(button->type_.get())->url_));
current_button.data = std::move(url); current_button.data = std::move(url);
if (!clean_input_string(current_button.data)) { if (!clean_input_string(current_button.data)) {
return Status::Error(400, "Inline keyboard button url must be encoded in UTF-8"); return Status::Error(400, "Inline keyboard button url must be encoded in UTF-8");

View File

@ -2596,8 +2596,7 @@ string FileManager::get_persistent_id(const FullRemoteFileLocation &location) {
Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType file_type) { Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType file_type) {
if (persistent_id.find('.') != string::npos) { if (persistent_id.find('.') != string::npos) {
string input_url = persistent_id.str(); // TODO do not copy persistent_id TRY_RESULT(http_url, parse_url(persistent_id));
TRY_RESULT(http_url, parse_url(input_url));
auto url = http_url.get_url(); auto url = http_url.get_url();
if (!clean_input_string(url)) { if (!clean_input_string(url)) {
return Status::Error(400, "URL must be in UTF-8"); return Status::Error(400, "URL must be in UTF-8");

View File

@ -275,7 +275,7 @@ string get_emoji_fingerprint(uint64 num) {
return emojis[static_cast<size_t>((num & 0x7FFFFFFFFFFFFFFF) % emojis.size())].str(); return emojis[static_cast<size_t>((num & 0x7FFFFFFFFFFFFFFF) % emojis.size())].str();
} }
Result<string> check_url(MutableSlice url) { Result<string> check_url(Slice url) {
bool is_tg = false; bool is_tg = false;
if (begins_with(url, "tg://")) { if (begins_with(url, "tg://")) {
url.remove_prefix(5); url.remove_prefix(5);

View File

@ -34,6 +34,6 @@ int32 get_vector_hash(const vector<uint32> &numbers) TD_WARN_UNUSED_RESULT;
string get_emoji_fingerprint(uint64 num); string get_emoji_fingerprint(uint64 num);
// checks whether url is a valid tg or HTTP(S) URL and returns its in a canonical form // checks whether url is a valid tg or HTTP(S) URL and returns its in a canonical form
Result<string> check_url(MutableSlice url); Result<string> check_url(Slice url);
} // namespace td } // namespace td

View File

@ -34,8 +34,7 @@ Wget::Wget(Promise<unique_ptr<HttpQuery>> promise, string url, std::vector<std::
} }
Status Wget::try_init() { Status Wget::try_init() {
string input_url = input_url_; TRY_RESULT(url, parse_url(input_url_));
TRY_RESULT(url, parse_url(MutableSlice(input_url)));
TRY_RESULT(ascii_host, idn_to_ascii(url.host_)); TRY_RESULT(ascii_host, idn_to_ascii(url.host_));
url.host_ = std::move(ascii_host); url.host_ = std::move(ascii_host);

View File

@ -187,10 +187,8 @@ string get_url_query_file_name(const string &query) {
return query_slice.str(); return query_slice.str();
} }
string get_url_file_name(const string &url) { string get_url_file_name(Slice url) {
// TODO remove copy auto r_http_url = parse_url(url);
string url_copy = url;
auto r_http_url = parse_url(url_copy);
if (r_http_url.is_error()) { if (r_http_url.is_error()) {
LOG(WARNING) << "Receive wrong URL \"" << url << '"'; LOG(WARNING) << "Receive wrong URL \"" << url << '"';
return string(); return string();

View File

@ -43,6 +43,6 @@ StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url);
string get_url_query_file_name(const string &query); string get_url_query_file_name(const string &query);
string get_url_file_name(const string &url); string get_url_file_name(Slice url);
} // namespace td } // namespace td