Merge pull request #1206 from ZeldaZach/fix_at_space

Fix Crash on Mention Bug
This commit is contained in:
Zach 2015-07-04 18:38:24 -04:00
commit c148994ac7

View file

@ -312,7 +312,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1); QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1);
QString mentionIntact = fullMentionUpToSpaceOrEnd; QString mentionIntact = fullMentionUpToSpaceOrEnd;
while (fullMentionUpToSpaceOrEnd.size()) do
{ {
if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this? if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this?
{ {
@ -343,7 +343,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
cursor.setCharFormat(defaultFormat); cursor.setCharFormat(defaultFormat);
break; break;
} }
else if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1) else if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2)
{ {
cursor.insertText("@" + mentionIntact, defaultFormat); cursor.insertText("@" + mentionIntact, defaultFormat);
message = message.mid(mentionIntact.size() + 1); message = message.mid(mentionIntact.size() + 1);
@ -352,9 +352,10 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
} }
else else
{ {
fullMentionUpToSpaceOrEnd = fullMentionUpToSpaceOrEnd.left(fullMentionUpToSpaceOrEnd.size() - 1); fullMentionUpToSpaceOrEnd.chop(1);
} }
} }
while (fullMentionUpToSpaceOrEnd.size());
} }
} }
else else