xirc: encode tokens in GenerateIsupport

This commit is contained in:
Simon Ser 2022-05-29 18:24:10 +02:00
parent c10d382a7d
commit fa6f52ed08
3 changed files with 10 additions and 8 deletions

View file

@ -1496,7 +1496,7 @@ func (dc *downstreamConn) welcome(ctx context.Context) error {
isupport = append(isupport, "BOT=B")
}
if title := dc.srv.Config().Title; dc.network == nil && title != "" {
isupport = append(isupport, "NETWORK="+encodeISUPPORT(title))
isupport = append(isupport, "NETWORK="+title)
}
if dc.network == nil && !dc.isMultiUpstream {
isupport = append(isupport, "WHOX")

6
irc.go
View file

@ -592,12 +592,6 @@ func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo)
}
}
var isupportEncoder = strings.NewReplacer(" ", "\\x20", "\\", "\\x5C")
func encodeISUPPORT(s string) string {
return isupportEncoder.Replace(s)
}
type capRegistry struct {
Available map[string]string
Enabled map[string]struct{}

View file

@ -84,6 +84,7 @@ func (js *joinSorter) Swap(i, j int) {
func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.Message {
maxTokens := maxMessageParams - 2 // 2 reserved params: nick + text
// TODO: take into account maxMessageLength as well
var msgs []*irc.Message
for len(tokens) > 0 {
var msgTokens []string
@ -95,16 +96,23 @@ func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.M
tokens = nil
}
encodedTokens := make([]string, len(msgTokens))
for i, tok := range msgTokens {
encodedTokens[i] = isupportEncoder.Replace(tok)
}
msgs = append(msgs, &irc.Message{
Prefix: prefix,
Command: irc.RPL_ISUPPORT,
Params: append(append([]string{nick}, msgTokens...), "are supported"),
Params: append(append([]string{nick}, encodedTokens...), "are supported"),
})
}
return msgs
}
var isupportEncoder = strings.NewReplacer(" ", "\\x20", "\\", "\\x5C")
func GenerateMOTD(prefix *irc.Prefix, nick string, motd string) []*irc.Message {
var msgs []*irc.Message
msgs = append(msgs, &irc.Message{