Correctly handle the usage of ! as a IRC user mode indicator

Since “!” is also the separator between the nickname and the user hostname,
having “!” as the user mode (e.g. !nick!~some@host.bla) would cause the nick
to be empty. Now we skip it if it is a valid user mode indicator.
This commit is contained in:
Florent Le Coz
2014-05-14 21:48:38 +02:00
parent 634e7cf125
commit 712b7bdfdf
2 changed files with 20 additions and 3 deletions
+17
View File
@@ -9,6 +9,7 @@
#include <config/config.hpp>
#include <bridge/colors.hpp>
#include <utils/tolower.hpp>
#include <irc/irc_user.hpp>
#include <utils/split.hpp>
#include <xmpp/jid.hpp>
#include <irc/iid.hpp>
@@ -122,6 +123,22 @@ int main()
assert(xml_escape(unescaped) == "&apos;coucou&apos;&lt;cc&gt;/&amp;&quot;gaga&quot;");
assert(xml_unescape(xml_escape(unescaped)) == unescaped);
/**
* Irc user parsing
*/
const std::map<char, char> prefixes{{'!', 'a'}, {'@', 'o'}};
IrcUser user1("!nick!~some@host.bla", prefixes);
assert(user1.nick == "nick");
assert(user1.host == "~some@host.bla");
assert(user1.modes.size() == 1);
assert(user1.modes.find('a') != user1.modes.end());
IrcUser user2("coucou!~other@host.bla", prefixes);
assert(user2.nick == "coucou");
assert(user2.host == "~other@host.bla");
assert(user2.modes.size() == 0);
assert(user2.modes.find('a') == user2.modes.end());
/**
* Colors conversion
*/