summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-02-11 23:57:17 +0300
committerAndrei Karas <akaras@inbox.ru>2014-02-11 23:57:17 +0300
commit165556c8ddf4d3a036d6d89e680e208d2b435866 (patch)
tree719d66843668bfb37cae499581960d2942c5b3fd /src
parentaf8863d722f06153877d289b939b5ba84713621d (diff)
downloadmv-165556c8ddf4d3a036d6d89e680e208d2b435866.tar.gz
mv-165556c8ddf4d3a036d6d89e680e208d2b435866.tar.bz2
mv-165556c8ddf4d3a036d6d89e680e208d2b435866.tar.xz
mv-165556c8ddf4d3a036d6d89e680e208d2b435866.zip
improve autocomplete sanitization.
Diffstat (limited to 'src')
-rw-r--r--src/gui/windows/chatwindow.cpp14
-rw-r--r--src/utils/stringutils.cpp6
-rw-r--r--src/utils/stringutils.h2
3 files changed, 12 insertions, 10 deletions
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 976a8dfd8..5b0bb69b6 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1312,7 +1312,6 @@ void ChatWindow::autoComplete()
const int caretPos = mChatInput->getCaretPosition();
int startName = 0;
const std::string inputText = mChatInput->getText();
- bool needSecure(false);
std::string name = inputText.substr(0, caretPos);
for (int f = caretPos - 1; f > -1; f --)
@@ -1335,15 +1334,15 @@ void ChatWindow::autoComplete()
if (cTab)
cTab->getAutoCompleteList(nameList);
std::string newName = autoComplete(nameList, name);
- if (!newName.empty())
- needSecure = true;
+ if (!newName.empty() && !startName)
+ secureChatCommand(newName);
if (newName.empty() && actorManager)
{
actorManager->getPlayerNames(nameList, true);
newName = autoComplete(nameList, name);
- if (!newName.empty())
- needSecure = true;
+ if (!newName.empty() && !startName)
+ secureChatCommand(newName);
}
if (newName.empty())
newName = autoCompleteHistory(name);
@@ -1366,11 +1365,6 @@ void ChatWindow::autoComplete()
if (!newName.empty())
{
- if (!startName && needSecure && (newName[0] == '/'
- || newName[0] == '@' || newName[0] == '#'))
- {
- newName = "_" + newName;
- }
mChatInput->setText(inputText.substr(0, startName).append(newName)
.append(inputText.substr(caretPos,
inputText.length() - caretPos)));
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 8e657bb93..224c2a8e8 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -721,3 +721,9 @@ bool isDigit(const std::string &str)
}
return true;
}
+
+void secureChatCommand(std::string &str)
+{
+ if (str[0] == '/' || str[0] == '@' || str[0] == '#')
+ str = "_" + str;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 02b1aa031..4a73b3e58 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -236,4 +236,6 @@ std::string decodeLinkText(std::string data);
bool isDigit(const std::string &str);
+void secureChatCommand(std::string &str);
+
#endif // UTILS_STRINGUTILS_H