Fixed crash on the byte length check.

This commit is contained in:
flash 2025-04-14 22:27:36 +00:00
parent 62ab8c0c93
commit 83cf6ae438
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
4 changed files with 6 additions and 4 deletions

View file

@ -30,7 +30,7 @@ namespace SharpChat {
StringInfo sti = new StringInfo(statusText);
if(Encoding.UTF8.GetByteCount(statusText) > AFKCommand.MAX_BYTES
|| sti.LengthInTextElements > AFKCommand.MAX_GRAPHEMES)
statusText = sti.SubstringByTextElements(0, AFKCommand.MAX_GRAPHEMES);
statusText = sti.SubstringByTextElements(0, Math.Min(sti.LengthInTextElements, AFKCommand.MAX_GRAPHEMES)).Trim();
sb.AppendFormat("<{0}>_", statusText.ToUpperInvariant());
}

View file

@ -1,4 +1,5 @@
using SharpChat.Packet;
using System;
using System.Globalization;
using System.Linq;
using System.Text;
@ -23,7 +24,7 @@ namespace SharpChat.Commands {
StringInfo sti = new StringInfo(statusText);
if(Encoding.UTF8.GetByteCount(statusText) > MAX_BYTES
|| sti.LengthInTextElements > MAX_GRAPHEMES)
statusText = sti.SubstringByTextElements(0, MAX_GRAPHEMES).Trim();
statusText = sti.SubstringByTextElements(0, Math.Min(sti.LengthInTextElements, MAX_GRAPHEMES)).Trim();
}
ctx.Chat.UpdateUser(

View file

@ -1,4 +1,5 @@
using SharpChat.Packet;
using System;
using System.Globalization;
using System.Linq;
using System.Text;
@ -47,7 +48,7 @@ namespace SharpChat.Commands {
StringInfo nsi = new StringInfo(nickStr);
if(Encoding.UTF8.GetByteCount(nickStr) > MAX_BYTES
|| nsi.LengthInTextElements > MAX_GRAPHEMES)
nickStr = nsi.SubstringByTextElements(0, MAX_GRAPHEMES).Trim();
nickStr = nsi.SubstringByTextElements(0, Math.Min(nsi.LengthInTextElements, MAX_GRAPHEMES)).Trim();
}
if(!string.IsNullOrWhiteSpace(nickStr) && ctx.Chat.Users.Any(u => u.NameEquals(nickStr))) {

View file

@ -60,7 +60,7 @@ namespace SharpChat.PacketHandlers
StringInfo messageTextInfo = new StringInfo(messageText);
if(Encoding.UTF8.GetByteCount(messageText) > (maxMsgLength * 10)
|| messageTextInfo.LengthInTextElements > maxMsgLength)
messageText = messageTextInfo.SubstringByTextElements(0, maxMsgLength);
messageText = messageTextInfo.SubstringByTextElements(0, Math.Min(messageTextInfo.LengthInTextElements, maxMsgLength));
messageText = messageText.Trim();