Skip to content

Commit 8f21913

Browse files
committed
HtmlText.Truncate ignores invalid & sequences
1 parent 2dc197c commit 8f21913

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/Telegram.Bot/Extensions/FormatExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,11 @@ public static string Truncate(string html, int count, string suffix = "…")
277277
for (; count > 0 && index < len; index++)
278278
{
279279
var c = html[index];
280-
if (c == '&')
281-
index = html.IndexOf(';', index + 1);
280+
if (c == '&' && index + 1 < len && html[index + 1] is >= 'a' and <= 'z' or >= 'A' and <= 'Z' or '#')
281+
{
282+
int end = html.IndexOf(';', index + 1);
283+
if (end > 0 && end - index < 10) index = end;
284+
}
282285
else if (c == '<')
283286
{
284287
int end = html.IndexOf('>', index + 1);

src/Telegram.Bot/ITelegramBotClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface ITelegramBotClient
6565

6666
public static partial class TelegramBotClientExtensions
6767
{
68-
/// <summary>Use this method to get basic info about a file download it. For the moment, bots can download filesof up to 20MB in size.</summary>
68+
/// <summary>Use this method to get basic info about a file and download it. For the moment, bots can download filesof up to 20MB in size.</summary>
6969
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
7070
/// <param name="fileId">File identifier to get info about</param>
7171
/// <param name="destination">Destination stream to write file to</param>

0 commit comments

Comments
 (0)