From effc112bed400d632368ca633d8a6600ea8c8aae Mon Sep 17 00:00:00 2001 From: David Athay Date: Mon, 13 Apr 2009 14:48:07 +0100 Subject: Fixed @'s in a user's nick --- src/gui/widgets/chattab.cpp | 3 +++ src/utils/stringutils.cpp | 13 +++++++++++++ src/utils/stringutils.h | 8 ++++++++ 3 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 1879a918..bbf71e83 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -163,6 +163,9 @@ void ChatTab::chatLog(std::string line, int own, bool ignoreRecord) tmp.nick = ""; lineColor = "##S"; } + + // check for @, # or [ in nick + tmp.nick = removeBadChars(tmp.nick); #ifdef EATHENA_SUPPORT if (tmp.nick.empty() && tmp.text.substr(0, 17) == "Visible GM status") diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 6a88a12e..2f9bc9a8 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -61,3 +61,16 @@ const char *ipToString(int address) return asciiIP; } + +std::string &removeBadChars(std::string &str) +{ + std::string::size_type pos; + do + { + pos = str.find_first_of("@#[]"); + if (pos != std::string::npos) + str.erase(pos, 1); + } while (pos != std::string::npos); + + return str; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 8b8b7bc2..872a8f52 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -65,4 +65,12 @@ template std::string toString(const T &arg) */ const char *ipToString(int address); +/** + * Removes bad characters from a string + * + * @param str the string to remove the bad chars from + * @return a reference to the string without bad chars + */ +std::string &removeBadChars(std::string &str); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2