From f9b3f29216e2e0750c6a05e67507fbebb52ab2ae Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sat, 13 Feb 2016 21:38:00 +1000 Subject: [PATCH] client: Handle capabilities better and more on-spec --- client/capabilities.go | 14 ++++++-------- client/handlers.go | 2 -- client/reactor_test.go | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/capabilities.go b/client/capabilities.go index a5846f6..f9c195b 100644 --- a/client/capabilities.go +++ b/client/capabilities.go @@ -63,14 +63,12 @@ func (cc *ClientCapabilities) AddCaps(tags ...string) { // EnableCaps enables the given capabilities. func (cc *ClientCapabilities) EnableCaps(caps ...string) { for _, name := range caps { - cc.Enabled[name] = true - } -} - -// DisableCaps disbles the given capabilities. -func (cc *ClientCapabilities) DisableCaps(caps ...string) { - for _, name := range caps { - delete(cc.Enabled, name) + if strings.HasPrefix(name, "-") { + name = strings.TrimPrefix(name, "-") + delete(cc.Enabled, name) + } else { + cc.Enabled[name] = true + } } } diff --git a/client/handlers.go b/client/handlers.go index fc139e4..f87cc73 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -41,8 +41,6 @@ func capHandler(event string, info eventmgr.InfoMap) { if subcommand == "ACK" { sc.Caps.EnableCaps(strings.Split(params[2], " ")...) - } else if subcommand == "NAK" { - sc.Caps.DisableCaps(strings.Split(params[2], " ")...) } else if subcommand == "LS" { if len(params) > 3 { sc.Caps.AddCaps(strings.Split(params[3], " ")...) diff --git a/client/reactor_test.go b/client/reactor_test.go index 73750d4..66ec131 100644 --- a/client/reactor_test.go +++ b/client/reactor_test.go @@ -281,6 +281,22 @@ func testServerConnection(t *testing.T, reactor Reactor, client *ServerConnectio sendMessage(conn, nil, "example.com", "CAP", client.Nick, "ACK", "sasl") + sendMessage(conn, nil, "example.com", "CAP", client.Nick, "DEL", "sasl") + + _, exists := client.Caps.Avaliable["sasl"] + if exists { + t.Error( + "SASL cap is still available on client after CAP DEL sasl", + ) + } + + _, exists = client.Caps.Enabled["sasl"] + if exists { + t.Error( + "SASL cap still enabled on client after CAP DEL sasl", + ) + } + // shutdown client reactor.Shutdown(" Get mad! ")