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") isupport = append(isupport, "BOT=B")
} }
if title := dc.srv.Config().Title; dc.network == nil && title != "" { 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 { if dc.network == nil && !dc.isMultiUpstream {
isupport = append(isupport, "WHOX") 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 { type capRegistry struct {
Available map[string]string Available map[string]string
Enabled map[string]struct{} 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 { func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.Message {
maxTokens := maxMessageParams - 2 // 2 reserved params: nick + text maxTokens := maxMessageParams - 2 // 2 reserved params: nick + text
// TODO: take into account maxMessageLength as well
var msgs []*irc.Message var msgs []*irc.Message
for len(tokens) > 0 { for len(tokens) > 0 {
var msgTokens []string var msgTokens []string
@ -95,16 +96,23 @@ func GenerateIsupport(prefix *irc.Prefix, nick string, tokens []string) []*irc.M
tokens = nil tokens = nil
} }
encodedTokens := make([]string, len(msgTokens))
for i, tok := range msgTokens {
encodedTokens[i] = isupportEncoder.Replace(tok)
}
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{
Prefix: prefix, Prefix: prefix,
Command: irc.RPL_ISUPPORT, Command: irc.RPL_ISUPPORT,
Params: append(append([]string{nick}, msgTokens...), "are supported"), Params: append(append([]string{nick}, encodedTokens...), "are supported"),
}) })
} }
return msgs return msgs
} }
var isupportEncoder = strings.NewReplacer(" ", "\\x20", "\\", "\\x5C")
func GenerateMOTD(prefix *irc.Prefix, nick string, motd string) []*irc.Message { func GenerateMOTD(prefix *irc.Prefix, nick string, motd string) []*irc.Message {
var msgs []*irc.Message var msgs []*irc.Message
msgs = append(msgs, &irc.Message{ msgs = append(msgs, &irc.Message{