diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index ad2cc5004..542d1f534 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -3818,6 +3818,9 @@ Status fix_formatted_text(string &text, vector &entities, bool al merge_new_entities(entities, find_entities(text, skip_bot_commands)); } + // new whitespace-only entities could be added after splitting of entities + remove_invalid_entities(text, entities); + // TODO MAX_MESSAGE_LENGTH and MAX_CAPTION_LENGTH return Status::OK(); diff --git a/test/message_entities.cpp b/test/message_entities.cpp index ae4b7a31b..9b20b0bd1 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -815,6 +815,11 @@ TEST(MessageEntities, fix_formatted_text) { "abc", {{td::MessageEntity::Type::Italic, 0, 2}, {td::MessageEntity::Type::Bold, 2, 1}}); check_fix_formatted_text("abc", {{td::MessageEntity::Type::Italic, 0, 1}, {td::MessageEntity::Type::Bold, 2, 1}}, "abc", {{td::MessageEntity::Type::Italic, 0, 1}, {td::MessageEntity::Type::Bold, 2, 1}}); + check_fix_formatted_text("@tests @tests", {{td::MessageEntity::Type::Italic, 0, 13}}, "@tests @tests", + {{td::MessageEntity::Type::Mention, 0, 6}, + {td::MessageEntity::Type::Italic, 0, 6}, + {td::MessageEntity::Type::Mention, 7, 6}, + {td::MessageEntity::Type::Italic, 7, 6}}); // _a*b*_ check_fix_formatted_text(