Check that button text isn't empty.

This commit is contained in:
levlam 2023-03-02 19:57:11 +03:00
parent da974f2e5e
commit 3dce19ca2b

View File

@ -443,6 +443,9 @@ static Result<KeyboardButton> get_keyboard_button(tl_object_ptr<td_api::keyboard
if (!clean_input_string(button->text_)) { if (!clean_input_string(button->text_)) {
return Status::Error(400, "Keyboard button text must be encoded in UTF-8"); return Status::Error(400, "Keyboard button text must be encoded in UTF-8");
} }
if (button->text_.empty()) {
return Status::Error(400, "Keyboard button text must be non-empty");
}
KeyboardButton current_button; KeyboardButton current_button;
current_button.text = std::move(button->text_); current_button.text = std::move(button->text_);
@ -527,16 +530,18 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
bool switch_inline_buttons_allowed) { bool switch_inline_buttons_allowed) {
CHECK(button != nullptr); CHECK(button != nullptr);
if (!clean_input_string(button->text_)) { if (!clean_input_string(button->text_)) {
return Status::Error(400, "Keyboard button text must be encoded in UTF-8"); return Status::Error(400, "Inline keyboard button text must be encoded in UTF-8");
}
if (button->text_.empty()) {
return Status::Error(400, "Inline keyboard button text must be non-empty");
}
if (button->type_ == nullptr) {
return Status::Error(400, "Inline keyboard button type must be non-empty");
} }
InlineKeyboardButton current_button; InlineKeyboardButton current_button;
current_button.text = std::move(button->text_); current_button.text = std::move(button->text_);
if (button->type_ == nullptr) {
return Status::Error(400, "Inline keyboard button type must be non-empty");
}
int32 button_type_id = button->type_->get_id(); int32 button_type_id = button->type_->get_id();
switch (button_type_id) { switch (button_type_id) {
case td_api::inlineKeyboardButtonTypeUrl::ID: { case td_api::inlineKeyboardButtonTypeUrl::ID: {