summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-05-14 15:04:08 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-05-14 15:33:30 +0200
commit060cb48094f6a9d187d4645ecb1ec4cd4f374931 (patch)
tree818d4ee9df262662344b158247d5bce0e51c993f
parent283c9d7ccffbcae0eee8fb3693597973b2fca55a (diff)
downloadweechat-060cb48094f6a9d187d4645ecb1ec4cd4f374931.zip
irc: ignore BATCH commands when capability "batch" is not enabled (issue #1292)
-rw-r--r--src/plugins/irc/irc-protocol.c7
-rw-r--r--tests/unit/plugins/irc/test-irc-protocol.cpp118
2 files changed, 122 insertions, 3 deletions
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index f4fab5a0c..239e3dbca 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -668,6 +668,10 @@ IRC_PROTOCOL_CALLBACK(batch)
IRC_PROTOCOL_MIN_PARAMS(1);
+ /* do nothing (but ignore BATCH) if capability "batch" is not enabled */
+ if (!weechat_hashtable_has_key (server->cap_list, "batch"))
+ return WEECHAT_RC_OK;
+
if (params[0][0] == '+')
{
/* start batch */
@@ -7784,7 +7788,8 @@ irc_protocol_recv_command (struct t_irc_server *server,
/* if message is not BATCH but has a batch tag, just store it for later */
if (!ignore_batch_tag
&& hash_tags
- && (weechat_strcasecmp (msg_command, "batch") != 0))
+ && (weechat_strcasecmp (msg_command, "batch") != 0)
+ && weechat_hashtable_has_key (server->cap_list, "batch"))
{
ptr_batch_ref = weechat_hashtable_get (hash_tags, "batch");
if (ptr_batch_ref)
diff --git a/tests/unit/plugins/irc/test-irc-protocol.cpp b/tests/unit/plugins/irc/test-irc-protocol.cpp
index 35781588e..067e32803 100644
--- a/tests/unit/plugins/irc/test-irc-protocol.cpp
+++ b/tests/unit/plugins/irc/test-irc-protocol.cpp
@@ -795,10 +795,124 @@ TEST(IrcProtocolWithServer, away)
/*
* Tests functions:
- * irc_protocol_cb_batch
+ * irc_protocol_cb_batch (without batch cap)
*/
-TEST(IrcProtocolWithServer, batch)
+TEST(IrcProtocolWithServer, batch_without_batch_cap)
+{
+ SRV_INIT_JOIN2;
+
+ /* not enough parameters */
+ RECV(":server BATCH");
+ CHECK_ERROR_PARAMS("batch", 0, 1);
+ RECV(":server BATCH +test");
+ CHECK_NO_MSG;
+
+ /* invalid reference: does not start with '+' or '-' */
+ RECV(":server BATCH zzz type");
+ CHECK_NO_MSG;
+ POINTERS_EQUAL(NULL, ptr_server->batches);
+
+ /* start batch without parameters */
+ RECV(":server BATCH +ref example");
+ CHECK_NO_MSG;
+ POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
+
+ /* new messages with batch reference */
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :this is a test");
+ CHECK_CHAN("bob this is a test");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :second test");
+ CHECK_CHAN("bob second test");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :third test");
+ CHECK_CHAN("bob third test");
+
+ /* end batch */
+ RECV(":server BATCH -ref");
+ CHECK_NO_MSG;
+
+ /* start batch with parameters */
+ RECV(":server BATCH +ref example param1 param2 param3");
+ CHECK_NO_MSG;
+ POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
+
+ /* new messages with batch reference */
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 1");
+ CHECK_CHAN("bob test 1");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 2");
+ CHECK_CHAN("bob test 2");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :test 3");
+ CHECK_CHAN("bob test 3");
+
+ /* end batch */
+ RECV(":server BATCH -ref");
+ CHECK_NO_MSG;
+
+ /* start/end batch without parameters */
+ RECV(":server BATCH +ref example");
+ RECV(":server BATCH -ref");
+ CHECK_NO_MSG;
+ POINTERS_EQUAL(NULL, irc_batch_search (ptr_server, "ref"));
+
+ /* interleaving batches */
+ RECV(":server BATCH +1 example");
+ CHECK_NO_MSG;
+ RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 1");
+ CHECK_CHAN("bob message 1");
+ RECV(":server BATCH +2 example");
+ CHECK_NO_MSG;
+ RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 2");
+ CHECK_CHAN("bob message 2");
+ RECV("@batch=2 :bob!user_b@host_b PRIVMSG #test :message 4");
+ CHECK_CHAN("bob message 4");
+ RECV("@batch=1 :bob!user_b@host_b PRIVMSG #test :message 3");
+ CHECK_CHAN("bob message 3");
+ RECV(":server BATCH -1");
+ CHECK_NO_MSG;
+ RECV("@batch=2 :bob!user_b@host_b PRIVMSG #test :message 5");
+ CHECK_CHAN("bob message 5");
+ RECV(":server BATCH -2");
+ CHECK_NO_MSG;
+
+ /* nested batch */
+ RECV(":server BATCH +ref1 example1");
+ CHECK_NO_MSG;
+ RECV("@batch=ref1 :server BATCH +ref2 example2");
+ RECV("@batch=ref1 :bob!user_b@host_b PRIVMSG #test :test ref1");
+ CHECK_CHAN("bob test ref1");
+ RECV("@batch=ref2 :bob!user_b@host_b PRIVMSG #test :test ref2");
+ CHECK_CHAN("bob test ref2");
+ RECV(":server BATCH -ref2");
+ CHECK_NO_MSG;
+ RECV(":server BATCH -ref1");
+ CHECK_NO_MSG;
+
+ /* multiline */
+ RECV(":server BATCH +ref draft/multiline #test");
+ CHECK_NO_MSG;
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 1");
+ CHECK_CHAN("bob line 1");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :line 2");
+ CHECK_CHAN("bob line 2");
+ RECV(":server BATCH -ref");
+ CHECK_NO_MSG;
+
+ /* multiline with CTCP */
+ RECV(":server BATCH +ref draft/multiline #test");
+ CHECK_NO_MSG;
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :\01ACTION is testing");
+ CHECK_CHAN(" * bob is testing");
+ RECV("@batch=ref :bob!user_b@host_b PRIVMSG #test :again\01");
+ CHECK_CHAN("bob again\01");
+ RECV(":server BATCH -ref");
+ CHECK_NO_MSG;
+}
+
+/*
+ * Tests functions:
+ * irc_protocol_cb_batch (with batch cap)
+ */
+
+TEST(IrcProtocolWithServer, batch_with_batch_cap)
{
struct t_irc_batch *ptr_batch;