From 865c841bd61760052856cd69176f13023bc6be91 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Tue, 4 Jun 2024 19:04:22 +0200 Subject: [PATCH] Html/Markdown: fix-up potential ENTITY_BOUNDS_INVALID --- src/Services.cs | 13 +++++++++++++ src/TL.Schema.cs | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/Services.cs b/src/Services.cs index 0be43f1..e051ffe 100644 --- a/src/Services.cs +++ b/src/Services.cs @@ -234,6 +234,7 @@ namespace TL } if (lastBlockQuote is { length: -1 }) lastBlockQuote.length = sb.Length - lastBlockQuote.offset; + HtmlText.FixUps(sb, entities); text = sb.ToString(); return entities.Count == 0 ? null : [.. entities]; } @@ -431,10 +432,22 @@ namespace TL else offset++; } + FixUps(sb, entities); text = sb.ToString(); return entities.Count == 0 ? null : [.. entities]; } + internal static void FixUps(StringBuilder sb, List entities) + { + int truncate = 0; + while (char.IsWhiteSpace(sb[^++truncate])); + if (truncate == 1) return; + var len = sb.Length -= --truncate; + foreach (var entity in entities) + if (entity.offset + entity.length > len) + entity.length = len - entity.offset; + } + /// Converts the (plain text + entities) format used by Telegram messages into an HTML-formatted text /// Client, used only for getting current user ID in case of InputMessageEntityMentionName+InputUserSelf /// The plain text, typically obtained from diff --git a/src/TL.Schema.cs b/src/TL.Schema.cs index f860984..1e447dc 100644 --- a/src/TL.Schema.cs +++ b/src/TL.Schema.cs @@ -4079,15 +4079,25 @@ namespace TL public Messages_StickerSet stickerset; } /// The order of stickersets was changed See - [TLDef(0x0BB2D201, inheritBefore = true)] - public sealed partial class UpdateStickerSetsOrder : UpdateStickerSets + [TLDef(0x0BB2D201)] + public sealed partial class UpdateStickerSetsOrder : Update { + /// Extra bits of information, use flags.HasFlag(...) to test for those + public Flags flags; /// New sticker order by sticker ID public long[] order; + + [Flags] public enum Flags : uint + { + /// Whether the updated stickers are mask stickers + masks = 0x1, + /// Whether the updated stickers are custom emoji stickers + emojis = 0x2, + } } /// Installed stickersets have changed, the client should refetch them as described in the docs. See [TLDef(0x31C24808)] - public partial class UpdateStickerSets : Update + public sealed partial class UpdateStickerSets : Update { /// Extra bits of information, use flags.HasFlag(...) to test for those public Flags flags;