From d8bc3d17bb10cef52dccc9a13e767dd01374b863 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 23 Sep 2026 21:58:20 -0500 Subject: [PATCH] IRC nicks cannot contain spaces Rather than trying and hoping the server gives a proper failure, just fail early and avoid the whole mess. Some servers will instead send messages to the user, etc, which is not very helpful. --- src/irc/irc_client.cpp | 5 +++++ tests/end_to_end/scenarios/nick_change_spaces.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/end_to_end/scenarios/nick_change_spaces.py diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index a3d1973..906e8e4 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -526,6 +526,11 @@ void IrcClient::send_user_command(const std::string& username, const std::string void IrcClient::send_nick_command(const std::string& nick) { + if (nick.find(' ') != std::string::npos) + { + this->on_erroneous_nickname(IrcMessage(std::string(this->hostname), "432", {this->get_own_nick(), nick, "Erroneous nickname"})); + return; + } this->send_message(IrcMessage("NICK", {nick})); } diff --git a/tests/end_to_end/scenarios/nick_change_spaces.py b/tests/end_to_end/scenarios/nick_change_spaces.py new file mode 100644 index 0000000..047e3cb --- /dev/null +++ b/tests/end_to_end/scenarios/nick_change_spaces.py @@ -0,0 +1,13 @@ +from scenarios import * + +scenario = ( + send_stanza(""), + sequences.connection(), + expect_stanza("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']"), + expect_stanza("/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + # Attempt to change nick to a nickname containing a space + send_stanza(""), + expect_stanza("/message[@from='{irc_server_one}'][@to='{jid_one}/{resource_one}']/body[text()='irc.localhost: Erroneous nickname: Nick With Space']"), +)