Skip to content

Commit

Permalink
Pass Slice to parse_url.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: e6cd357042b827ca56a11bb377c8b07ccd120230
  • Loading branch information
levlam committed Aug 5, 2019
1 parent 84b33cd commit ad167a4
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion td/telegram/InlineQueriesManager.cpp
Expand Up @@ -1072,7 +1072,7 @@ string InlineQueriesManager::get_web_document_url(const tl_object_ptr<telegram_a
return {};
}

string url;
Slice url;
switch (web_document_ptr->get_id()) {
case telegram_api::webDocument::ID: {
auto web_document = static_cast<const telegram_api::webDocument *>(web_document_ptr.get());
Expand Down
3 changes: 1 addition & 2 deletions td/telegram/MessageEntity.cpp
Expand Up @@ -1872,8 +1872,7 @@ vector<MessageEntity> get_message_entities(const ContactsManager *contacts_manag
break;
}
case telegram_api::messageEntityTextUrl::ID: {
// TODO const telegram_api::messageEntityTextUrl *
auto entity_text_url = static_cast<telegram_api::messageEntityTextUrl *>(entity.get());
auto entity_text_url = static_cast<const telegram_api::messageEntityTextUrl *>(entity.get());
auto r_url = check_url(entity_text_url->url_);
if (r_url.is_error()) {
LOG(ERROR) << "Wrong URL entity: \"" << entity_text_url->url_ << "\": " << r_url.error().message() << " from "
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/ReplyMarkup.cpp
Expand Up @@ -380,7 +380,7 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
switch (button_type_id) {
case td_api::inlineKeyboardButtonTypeUrl::ID: {
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);
if (!clean_input_string(current_button.data)) {
return Status::Error(400, "Inline keyboard button url must be encoded in UTF-8");
Expand Down
3 changes: 1 addition & 2 deletions td/telegram/files/FileManager.cpp
Expand Up @@ -2596,8 +2596,7 @@ string FileManager::get_persistent_id(const FullRemoteFileLocation &location) {

Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType file_type) {
if (persistent_id.find('.') != string::npos) {
string input_url = persistent_id.str(); // TODO do not copy persistent_id
TRY_RESULT(http_url, parse_url(input_url));
TRY_RESULT(http_url, parse_url(persistent_id));
auto url = http_url.get_url();
if (!clean_input_string(url)) {
return Status::Error(400, "URL must be in UTF-8");
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/misc.cpp
Expand Up @@ -275,7 +275,7 @@ string get_emoji_fingerprint(uint64 num) {
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;
if (begins_with(url, "tg://")) {
url.remove_prefix(5);
Expand Down
2 changes: 1 addition & 1 deletion td/telegram/misc.h
Expand Up @@ -34,6 +34,6 @@ int32 get_vector_hash(const vector<uint32> &numbers) TD_WARN_UNUSED_RESULT;
string get_emoji_fingerprint(uint64 num);

// 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
3 changes: 1 addition & 2 deletions tdnet/td/net/Wget.cpp
Expand Up @@ -34,8 +34,7 @@ Wget::Wget(Promise<unique_ptr<HttpQuery>> promise, string url, std::vector<std::
}

Status Wget::try_init() {
string input_url = input_url_;
TRY_RESULT(url, parse_url(MutableSlice(input_url)));
TRY_RESULT(url, parse_url(input_url_));
TRY_RESULT(ascii_host, idn_to_ascii(url.host_));
url.host_ = std::move(ascii_host);

Expand Down
6 changes: 2 additions & 4 deletions tdutils/td/utils/HttpUrl.cpp
Expand Up @@ -187,10 +187,8 @@ string get_url_query_file_name(const string &query) {
return query_slice.str();
}

string get_url_file_name(const string &url) {
// TODO remove copy
string url_copy = url;
auto r_http_url = parse_url(url_copy);
string get_url_file_name(Slice url) {
auto r_http_url = parse_url(url);
if (r_http_url.is_error()) {
LOG(WARNING) << "Receive wrong URL \"" << url << '"';
return string();
Expand Down
2 changes: 1 addition & 1 deletion tdutils/td/utils/HttpUrl.h
Expand Up @@ -43,6 +43,6 @@ StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url);

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

0 comments on commit ad167a4

Please sign in to comment.