1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(core): split messages on utf8 multibyte character boundary properly

Fix #4917
This commit is contained in:
Anthony Bilinski 2018-04-11 23:07:05 -07:00
parent 04ecfe3f34
commit 869036f3c6
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -1392,15 +1392,17 @@ QStringList Core::splitMessage(const QString& message, int maxLen)
}
if (splitPos <= 0) {
constexpr uint8_t firstOfMultiByteMask = 0xC0;
constexpr uint8_t multiByteMask = 0x80;
splitPos = maxLen;
if (ba_message[splitPos] & 0x80) {
do {
// don't split a utf8 character
if ((ba_message[splitPos] & multiByteMask) == multiByteMask) {
while ((ba_message[splitPos] & firstOfMultiByteMask) != firstOfMultiByteMask) {
--splitPos;
} while (!(ba_message[splitPos] & 0x40));
}
}
--splitPos;
}
splittedMsgs.append(QString{ba_message.left(splitPos + 1)});
ba_message = ba_message.mid(splitPos + 1);
}