@@ -713,6 +713,74 @@ RichText RichText::get_quote_fragment_impl(size_t &pos, size_t begin, size_t end
713713 }
714714}
715715
716+ bool RichText::remove_unallowed_quote_entities () {
717+ switch (type_) {
718+ case Type::Plain:
719+ case Type::Math:
720+ case Type::CustomEmoji:
721+ return false ;
722+ case Type::Icon:
723+ // icons can't be quoted
724+ *this = RichText ();
725+ return true ;
726+ case Type::Concatenation: {
727+ bool is_changed = false ;
728+ for (auto &text : texts_) {
729+ if (text.remove_unallowed_quote_entities ()) {
730+ is_changed = true ;
731+ }
732+ }
733+ if (td::remove_if (texts_, [](const RichText &text) { return text.empty (); })) {
734+ is_changed = true ;
735+ }
736+ if (texts_.empty ()) {
737+ *this = RichText ();
738+ return true ;
739+ }
740+ return is_changed;
741+ }
742+ case Type::Fixed:
743+ case Type::Url:
744+ case Type::EmailAddress:
745+ case Type::Marked:
746+ case Type::PhoneNumber:
747+ case Type::Anchor:
748+ case Type::Mention:
749+ case Type::Hashtag:
750+ case Type::Cashtag:
751+ case Type::BotCommand:
752+ case Type::AutoUrl:
753+ case Type::AutoEmailAddress:
754+ case Type::AutoPhoneNumber:
755+ case Type::BankCardNumber:
756+ case Type::MentionName:
757+ case Type::Button:
758+ case Type::TonAddress:
759+ case Type::Diff: {
760+ // the formatting isn't supported in quotes, so only the text is kept
761+ CHECK (!texts_.empty ());
762+ auto text = std::move (texts_[0 ]);
763+ text.remove_unallowed_quote_entities ();
764+ *this = std::move (text);
765+ return true ;
766+ }
767+ default :
768+ if (texts_.size () != 1u ) {
769+ LOG (ERROR ) << " Receive rich text of type " << static_cast <int32>(type_) << " with " << texts_.size ()
770+ << " texts" ;
771+ *this = RichText ();
772+ return true ;
773+ }
774+ if (!texts_[0 ].remove_unallowed_quote_entities ()) {
775+ return false ;
776+ }
777+ if (texts_[0 ].empty ()) {
778+ *this = RichText ();
779+ }
780+ return true ;
781+ }
782+ }
783+
716784int32 RichText::get_index_mask () const {
717785 switch (type_) {
718786 case Type::Url:
0 commit comments