Skip to content

Commit 9352aff

Browse files
committed
fix(basechat): fix pasting strings that overflow and end with multibyte+singlebyte
1 parent f89154b commit 9352aff

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/game/client/hud_basechat.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,12 +2553,15 @@ void CBaseHudChatEntry::InsertChar(wchar_t ch)
25532553
return;
25542554
}
25552555

2556+
/* Pasting strings that overflow and end with multibyte+singlebyte will truncate unintuitively ("...ABC?!!" -> "...AB?")
25562557
// Edge case: check if current wchar_t will cause Send to truncate message
25572558
int iCharByteLen; // utf-8
25582559
if ( ch < 0x80 ) iCharByteLen = 1;
25592560
else if ( ch < 0x800 ) iCharByteLen = 2;
25602561
else if ( ch >= 0xD800 && ch <= 0xDBFF ) iCharByteLen = 4; // high surrogate, assume pair
25612562
else if ( ch >= 0xDC00 && ch <= 0xDFFF ) // low surrogate
2563+
*/
2564+
if ( ch >= 0xDC00 && ch <= 0xDFFF ) // low surrogate
25622565
{
25632566
// Check if previous wchar was a high surrogate
25642567
wchar_t wszHigh[2];
@@ -2567,13 +2570,15 @@ void CBaseHudChatEntry::InsertChar(wchar_t ch)
25672570
if ( wszHigh[0] >= 0xD800 && wszHigh[0] <= 0xDBFF ) { BaseClass::InsertChar(ch); return; }
25682571
else return; // it was not a hight surrogate, reject
25692572
}
2573+
/*
25702574
else iCharByteLen = 3;
25712575
25722576
if ( iCurrentByteLen + iCharByteLen <= m_iMaxByteCount )
25732577
{
25742578
BaseClass::InsertChar(ch);
25752579
return;
25762580
}
2581+
*/
25772582

25782583
return; // do not insert anything
25792584
}

0 commit comments

Comments
 (0)