Fix remove_invalid_entities.

GitOrigin-RevId: 6cad36ac6017dcc3870411129a1b0512f9351d17
This commit is contained in:
levlam 2020-07-13 15:34:56 +03:00
parent b5ae6b5b95
commit 8a1ffe0cbb
2 changed files with 11 additions and 4 deletions

View File

@ -3513,11 +3513,9 @@ static std::pair<size_t, int32> remove_invalid_entities(const string &text, vect
int32 last_space_utf16_offset = -1;
int32 last_non_whitespace_utf16_offset = -1;
td::remove_if(entities, [](const auto &entity) { return entity.length == 0; });
for (size_t pos = 0; pos <= text.size(); pos++) {
while (current_entity < entities.size() && utf16_offset >= entities[current_entity].offset &&
entities[current_entity].length == 0) {
nested_entities_stack.push_back(&entities[current_entity++]);
}
while (!nested_entities_stack.empty()) {
auto *entity = nested_entities_stack.back();
auto entity_end = entity->offset + entity->length;

View File

@ -813,6 +813,15 @@ TEST(MessageEntities, fix_formatted_text) {
check_fix_formatted_text(text, {{type, 0, 1, "http://telegram.org/"}}, "", {}, true, false, false, true);
}
}
check_fix_formatted_text("\r ", {{td::MessageEntity::Type::Bold, 0, 2}, {td::MessageEntity::Type::Underline, 0, 1}},
"", {}, true, false, false, true);
check_fix_formatted_text("a \r", {{td::MessageEntity::Type::Bold, 0, 3}, {td::MessageEntity::Type::Underline, 2, 1}},
"a ", {{td::MessageEntity::Type::Bold, 0, 2}}, true, false, false, true);
check_fix_formatted_text("a \r ", {{td::MessageEntity::Type::Bold, 0, 4}, {td::MessageEntity::Type::Underline, 2, 1}},
"a ", {{td::MessageEntity::Type::Bold, 0, 2}}, true, false, false, true);
check_fix_formatted_text(
"a \r b", {{td::MessageEntity::Type::Bold, 0, 5}, {td::MessageEntity::Type::Underline, 2, 1}}, "a b",
{{td::MessageEntity::Type::Bold, 0, 2}, {td::MessageEntity::Type::Bold, 3, 1}}, true, false, false, true);
check_fix_formatted_text("a\rbc\r",
{{td::MessageEntity::Type::Italic, 0, 1},