mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
irc: fix extraction of address from prefix
Do not return the nick when the address is missing.
This commit is contained in:
@@ -634,31 +634,27 @@ irc_message_get_address_from_host (const char *host)
|
||||
return NULL;
|
||||
|
||||
address[0] = '\0';
|
||||
if (host)
|
||||
{
|
||||
ptr_host = host;
|
||||
pos_space = strchr (host, ' ');
|
||||
if (pos_space)
|
||||
{
|
||||
if (pos_space - host < (int)sizeof (host2))
|
||||
{
|
||||
strncpy (host2, host, pos_space - host);
|
||||
host2[pos_space - host] = '\0';
|
||||
}
|
||||
else
|
||||
snprintf (host2, sizeof (host2), "%s", host);
|
||||
ptr_host = host2;
|
||||
}
|
||||
|
||||
if (ptr_host[0] == ':')
|
||||
ptr_host++;
|
||||
pos = strchr (ptr_host, '!');
|
||||
if (pos)
|
||||
snprintf (address, sizeof (address), "%s", pos + 1);
|
||||
ptr_host = host;
|
||||
pos_space = strchr (host, ' ');
|
||||
if (pos_space)
|
||||
{
|
||||
if (pos_space - host < (int)sizeof (host2))
|
||||
{
|
||||
strncpy (host2, host, pos_space - host);
|
||||
host2[pos_space - host] = '\0';
|
||||
}
|
||||
else
|
||||
snprintf (address, sizeof (address), "%s", ptr_host);
|
||||
snprintf (host2, sizeof (host2), "%s", host);
|
||||
ptr_host = host2;
|
||||
}
|
||||
|
||||
if (ptr_host[0] == ':')
|
||||
ptr_host++;
|
||||
pos = strchr (ptr_host, '!');
|
||||
if (pos)
|
||||
snprintf (address, sizeof (address), "%s", pos + 1);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
|
||||
@@ -912,19 +912,13 @@ TEST(IrcMessage, GetAddressFromHost)
|
||||
{
|
||||
POINTERS_EQUAL(NULL, irc_message_get_address_from_host (NULL));
|
||||
STRCMP_EQUAL("", irc_message_get_address_from_host (""));
|
||||
STRCMP_EQUAL("host", irc_message_get_address_from_host ("host"));
|
||||
STRCMP_EQUAL("host", irc_message_get_address_from_host ("host "));
|
||||
STRCMP_EQUAL("host", irc_message_get_address_from_host ("host test"));
|
||||
STRCMP_EQUAL("host", irc_message_get_address_from_host (":host "));
|
||||
STRCMP_EQUAL("", irc_message_get_address_from_host ("host"));
|
||||
STRCMP_EQUAL("", irc_message_get_address_from_host ("host "));
|
||||
STRCMP_EQUAL("", irc_message_get_address_from_host ("host test"));
|
||||
STRCMP_EQUAL("", irc_message_get_address_from_host (":host "));
|
||||
STRCMP_EQUAL("host", irc_message_get_address_from_host (":nick!host"));
|
||||
STRCMP_EQUAL("user@host",
|
||||
irc_message_get_address_from_host (":nick!user@host"));
|
||||
STRCMP_EQUAL("nick_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
"x_64_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
"xxxx_128_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
"xxxxxxxxxxxx_25",
|
||||
irc_message_get_address_from_host (NICK_256_WITH_SPACE));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user