From 1bb59a3261d00cf6cb641cf8aecb19535769daea Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 10 Dec 2019 05:46:58 +0300 Subject: [PATCH] Support new entity types in parse_html. GitOrigin-RevId: 1a12c3736f4e0921f133b3ac914620b4a01f0efe --- td/telegram/MessageEntity.cpp | 7 ++++++- test/message_entities.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index a1325e80..603c0658 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -1759,7 +1759,8 @@ static Result> do_parse_html(CSlice text, string &result) } string tag_name = to_lower(text.substr(begin_pos + 1, i - begin_pos - 1)); - if (tag_name != "em" && tag_name != "strong" && tag_name != "a" && tag_name != "b" && tag_name != "i" && + if (tag_name != "a" && tag_name != "b" && tag_name != "strong" && tag_name != "i" && tag_name != "em" && + tag_name != "s" && tag_name != "strike" && tag_name != "del" && tag_name != "u" && tag_name != "ins" && tag_name != "pre" && tag_name != "code") { return Status::Error(400, PSLICE() << "Unsupported start tag \"" << tag_name << "\" at byte offset " << begin_pos); @@ -1870,6 +1871,10 @@ static Result> do_parse_html(CSlice text, string &result) entities.emplace_back(MessageEntity::Type::Italic, entity_offset, entity_length); } else if (tag_name == "b" || tag_name == "strong") { entities.emplace_back(MessageEntity::Type::Bold, entity_offset, entity_length); + } else if (tag_name == "s" || tag_name == "strike" || tag_name == "del") { + entities.emplace_back(MessageEntity::Type::Strikethrough, entity_offset, entity_length); + } else if (tag_name == "u" || tag_name == "ins") { + entities.emplace_back(MessageEntity::Type::Underline, entity_offset, entity_length); } else if (tag_name == "a") { auto url = std::move(nested_entities.back().argument); if (url.empty()) { diff --git a/test/message_entities.cpp b/test/message_entities.cpp index 5de00f9a..96befe50 100644 --- a/test/message_entities.cpp +++ b/test/message_entities.cpp @@ -776,6 +776,22 @@ TEST(MessageEntities, parse_html) { check_parse_html("<>&"«»�", "<>&\"«»�", {}); check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", {{td::MessageEntity::Type::Italic, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Italic, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Bold, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Bold, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Underline, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Underline, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Strikethrough, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Strikethrough, 5, 5}}); + check_parse_html("➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️", + {{td::MessageEntity::Type::Strikethrough, 5, 5}}); check_parse_html("➡️ ➡️➡️ ➡️➡️ ➡️", "➡️ ➡️➡️ ➡️➡️ ➡️", {{td::MessageEntity::Type::Italic, 5, 5}, {td::MessageEntity::Type::Bold, 10, 5}}); check_parse_html("🏟 🏟🏟 <🏟", "🏟 🏟🏟 <🏟", {{td::MessageEntity::Type::Italic, 5, 6}});