From 06e74cfba9fd1274805dc96a4da0444a8ee5923f Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Apr 2020 00:57:00 +0300 Subject: [PATCH] Remove whitespace-only entities added in merge_entities. GitOrigin-RevId: 8b2dbe05d0758639c4447fbfec038b8350dfda9a --- td/telegram/MessageEntity.cpp | 3 +++ test/message_entities.cpp | 5 +++++ 2 files changed, 8 insertions(+) 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(