From aaeab22ea3d4df73e8ee0d0c2870b6cd650d0076 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 11 May 2025 18:35:05 +0100 Subject: [PATCH] Fix processing of multi-token CAP ACK I broke it in 5943bc9ed91114d9a389e74f3b54b5d8279268c4 while fixing #1950 --- src/IRCSock.cpp | 16 +++++++++------- test/integration/tests/core.cpp | 3 ++- test/integration/tests/modules.cpp | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/IRCSock.cpp b/src/IRCSock.cpp index db32d1f5..aae8dc97 100644 --- a/src/IRCSock.cpp +++ b/src/IRCSock.cpp @@ -450,17 +450,19 @@ bool CIRCSock::OnCapabilityMessage(CMessage& Message) { } } } else if (sSubCmd == "ACK") { - sArgs.Trim(); - IRCSOCKMODULECALL(OnServerCapResult(sArgs, true), NOTHING); - auto it = mSupportedCaps.find(sArgs); - if (it != mSupportedCaps.end()) { - it->second(true); + VCString vsCaps; + sArgs.Split(" ", vsCaps, false); + for (CString& sCap : vsCaps) { + IRCSOCKMODULECALL(OnServerCapResult(sCap, true), NOTHING); + auto it = mSupportedCaps.find(sCap); + if (it != mSupportedCaps.end()) { + it->second(true); + } + m_ssAcceptedCaps.insert(std::move(sCap)); } - m_ssAcceptedCaps.insert(sArgs); } else if (sSubCmd == "NAK") { // This should work because there's no [known] // capability with length of name more than 100 characters. - sArgs.Trim(); VCString vsCaps; sArgs.Split(" ", vsCaps, false); if (vsCaps.size() == 1) { diff --git a/test/integration/tests/core.cpp b/test/integration/tests/core.cpp index 0aa6c373..b494ce07 100644 --- a/test/integration/tests/core.cpp +++ b/test/integration/tests/core.cpp @@ -21,6 +21,7 @@ #include "znctestconfig.h" using testing::HasSubstr; +using testing::Contains; using testing::ContainsRegex; using testing::SizeIs; using testing::Lt; @@ -1169,7 +1170,7 @@ TEST_F(ZNCTest, ManyCapsInReq) { ircd.ReadUntilAndGet("CAP REQ :", caps3); caps3.remove(0, prefix); EXPECT_THAT(caps3.toStdString(), Not(HasSubstr(" "))); - EXPECT_TRUE(caps.split(' ').contains(caps3)); + EXPECT_THAT(caps.split(' '), Contains(caps3)); } TEST_F(ZNCTest, JoinWhileRegistration) { diff --git a/test/integration/tests/modules.cpp b/test/integration/tests/modules.cpp index 652fccb4..929a8e9b 100644 --- a/test/integration/tests/modules.cpp +++ b/test/integration/tests/modules.cpp @@ -305,9 +305,9 @@ TEST_P(SaslModuleTest, Test) { client.Write("znc jump"); ircd = ConnectIRCd(); ircd.ReadUntil("CAP LS"); - ircd.Write("CAP * LS :sasl"); - ircd.ReadUntil("CAP REQ :sasl"); - ircd.Write("CAP * ACK :sasl"); + ircd.Write("CAP * LS :away-notify sasl"); + ircd.ReadUntil("CAP REQ :away-notify sasl"); + ircd.Write("CAP * ACK :away-notify sasl"); ircd.ReadUntil("AUTHENTICATE EXTERNAL"); ircd.Write(":server 904 *"); ircd.ReadUntil("AUTHENTICATE PLAIN");