Procházet zdrojové kódy

don't send multiline responses to CAP LS 301 (#2068)

* don't send multiline responses to CAP LS 301

This is more or less explicitly prohibited by the spec:

https://ircv3.net/specs/extensions/capability-negotiation.html#multiline-replies-to-cap-ls-and-cap-list

* switch to whitelist model to be future-proof

* bump irctest to include test

* add a unit test
tags/v2.12.0-rc1
Shivaram Lingamneni před 11 měsíci
rodič
revize
d082ec7ab9
Žádný účet není propojen s e-mailovou adresou tvůrce revize
3 změnil soubory, kde provedl 38 přidání a 3 odebrání
  1. 19
    0
      irc/caps/set.go
  2. 18
    2
      irc/caps/set_test.go
  3. 1
    1
      irctest

+ 19
- 0
irc/caps/set.go Zobrazit soubor

@@ -102,6 +102,13 @@ func (s *Set) Strings(version Version, values Values, maxLen int) (result []stri
102 102
 	var capab Capability
103 103
 	asSlice := s[:]
104 104
 	for capab = 0; capab < numCapabs; capab++ {
105
+		// XXX clients that only support CAP LS 301 cannot handle multiline
106
+		// responses. omit some CAPs in this case, forcing the response to fit on
107
+		// a single line. this is technically buggy for CAP LIST (as opposed to LS)
108
+		// but it shouldn't matter
109
+		if version < Cap302 && !isAllowed301(capab) {
110
+			continue
111
+		}
105 112
 		// skip any capabilities that are not enabled
106 113
 		if !utils.BitsetGet(asSlice, uint(capab)) {
107 114
 			continue
@@ -122,3 +129,15 @@ func (s *Set) Strings(version Version, values Values, maxLen int) (result []stri
122 129
 	}
123 130
 	return
124 131
 }
132
+
133
+// this is a fixed whitelist of caps that are eligible for display in CAP LS 301
134
+func isAllowed301(capab Capability) bool {
135
+	switch capab {
136
+	case AccountNotify, AccountTag, AwayNotify, Batch, ChgHost, Chathistory, EventPlayback,
137
+		Relaymsg, EchoMessage, Nope, ExtendedJoin, InviteNotify, LabeledResponse, MessageTags,
138
+		MultiPrefix, SASL, ServerTime, SetName, STS, UserhostInNames, ZNCSelfMessage, ZNCPlayback:
139
+		return true
140
+	default:
141
+		return false
142
+	}
143
+}

+ 18
- 2
irc/caps/set_test.go Zobrazit soubor

@@ -3,8 +3,11 @@
3 3
 
4 4
 package caps
5 5
 
6
-import "testing"
7
-import "reflect"
6
+import (
7
+	"fmt"
8
+	"reflect"
9
+	"testing"
10
+)
8 11
 
9 12
 func TestSets(t *testing.T) {
10 13
 	s1 := NewSet()
@@ -60,6 +63,19 @@ func TestSets(t *testing.T) {
60 63
 	}
61 64
 }
62 65
 
66
+func assertEqual(found, expected interface{}) {
67
+	if !reflect.DeepEqual(found, expected) {
68
+		panic(fmt.Sprintf("found %#v, expected %#v", found, expected))
69
+	}
70
+}
71
+
72
+func Test301WhitelistNotRespectedFor302(t *testing.T) {
73
+	s1 := NewSet()
74
+	s1.Enable(AccountTag, EchoMessage, StandardReplies)
75
+	assertEqual(s1.Strings(Cap301, nil, 0), []string{"account-tag echo-message"})
76
+	assertEqual(s1.Strings(Cap302, nil, 0), []string{"account-tag echo-message standard-replies"})
77
+}
78
+
63 79
 func TestSubtract(t *testing.T) {
64 80
 	s1 := NewSet(AccountTag, EchoMessage, UserhostInNames, ServerTime)
65 81
 

+ 1
- 1
irctest

@@ -1 +1 @@
1
-Subproject commit bb8a6b6c3d3e55c1146c3c9f8224983d88a42b17
1
+Subproject commit 22c6743b24f2a85bf79a92fb0c7fab325c047a6c

Načítá se…
Zrušit
Uložit