From fa6f52ed08e9735417ffdce2713124c31f161a92 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 29 May 2022 18:24:10 +0200 Subject: [PATCH] xirc: encode tokens in GenerateIsupport --- downstream.go | 2 +- irc.go | 6 ------ xirc/genmsg.go | 10 +++++++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/downstream.go b/downstream.go index d799878..7564ca0 100644 --- a/downstream.go +++ b/downstream.go @@ -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") diff --git a/irc.go b/irc.go index df11f87..a7d1260 100644 --- a/irc.go +++ b/irc.go @@ -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{} diff --git a/xirc/genmsg.go b/xirc/genmsg.go index 134bf0c..a4abc1c 100644 --- a/xirc/genmsg.go +++ b/xirc/genmsg.go @@ -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{