Fixed crash on the byte length check.
This commit is contained in:
parent
62ab8c0c93
commit
83cf6ae438
4 changed files with 6 additions and 4 deletions
SharpChat
|
@ -30,7 +30,7 @@ namespace SharpChat {
|
||||||
StringInfo sti = new StringInfo(statusText);
|
StringInfo sti = new StringInfo(statusText);
|
||||||
if(Encoding.UTF8.GetByteCount(statusText) > AFKCommand.MAX_BYTES
|
if(Encoding.UTF8.GetByteCount(statusText) > AFKCommand.MAX_BYTES
|
||||||
|| sti.LengthInTextElements > AFKCommand.MAX_GRAPHEMES)
|
|| 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());
|
sb.AppendFormat("<{0}>_", statusText.ToUpperInvariant());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.Packet;
|
||||||
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -23,7 +24,7 @@ namespace SharpChat.Commands {
|
||||||
StringInfo sti = new StringInfo(statusText);
|
StringInfo sti = new StringInfo(statusText);
|
||||||
if(Encoding.UTF8.GetByteCount(statusText) > MAX_BYTES
|
if(Encoding.UTF8.GetByteCount(statusText) > MAX_BYTES
|
||||||
|| sti.LengthInTextElements > MAX_GRAPHEMES)
|
|| 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(
|
ctx.Chat.UpdateUser(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using SharpChat.Packet;
|
using SharpChat.Packet;
|
||||||
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -47,7 +48,7 @@ namespace SharpChat.Commands {
|
||||||
StringInfo nsi = new StringInfo(nickStr);
|
StringInfo nsi = new StringInfo(nickStr);
|
||||||
if(Encoding.UTF8.GetByteCount(nickStr) > MAX_BYTES
|
if(Encoding.UTF8.GetByteCount(nickStr) > MAX_BYTES
|
||||||
|| nsi.LengthInTextElements > MAX_GRAPHEMES)
|
|| 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))) {
|
if(!string.IsNullOrWhiteSpace(nickStr) && ctx.Chat.Users.Any(u => u.NameEquals(nickStr))) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace SharpChat.PacketHandlers
|
||||||
StringInfo messageTextInfo = new StringInfo(messageText);
|
StringInfo messageTextInfo = new StringInfo(messageText);
|
||||||
if(Encoding.UTF8.GetByteCount(messageText) > (maxMsgLength * 10)
|
if(Encoding.UTF8.GetByteCount(messageText) > (maxMsgLength * 10)
|
||||||
|| messageTextInfo.LengthInTextElements > maxMsgLength)
|
|| messageTextInfo.LengthInTextElements > maxMsgLength)
|
||||||
messageText = messageTextInfo.SubstringByTextElements(0, maxMsgLength);
|
messageText = messageTextInfo.SubstringByTextElements(0, Math.Min(messageTextInfo.LengthInTextElements, maxMsgLength));
|
||||||
|
|
||||||
messageText = messageText.Trim();
|
messageText = messageText.Trim();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue