Fix parsing wrong empty element in RPL_WHOISCHANNELS channel list
Some servers add a trailing space to the channel list in RPL_WHOISCHANNELS. This commit works around this issue by removing any empty trailing element after splitting. Since RPL_WHOISCHANNELS could send an empty channel parameter, we can't just use strings.TrimRight(s, " "), because splitting on an empty string would still return an empty element. Closes: https://todo.sr.ht/~emersion/soju/25
This commit is contained in:
parent
2fff645129
commit
f08063c943
13
upstream.go
13
upstream.go
@ -821,14 +821,13 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
|||||||
if err := parseMessageParams(msg, nil, &statusStr, &name, &members); err != nil {
|
if err := parseMessageParams(msg, nil, &statusStr, &name, &members); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
members = strings.TrimRight(members, " ")
|
|
||||||
|
|
||||||
ch, ok := uc.channels[name]
|
ch, ok := uc.channels[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
// NAMES on a channel we have not joined, forward to downstream
|
// NAMES on a channel we have not joined, forward to downstream
|
||||||
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
||||||
channel := dc.marshalChannel(uc, name)
|
channel := dc.marshalChannel(uc, name)
|
||||||
members := strings.Split(members, " ")
|
members := splitSpace(members)
|
||||||
for i, member := range members {
|
for i, member := range members {
|
||||||
membership, nick := uc.parseMembershipPrefix(member)
|
membership, nick := uc.parseMembershipPrefix(member)
|
||||||
members[i] = membership.String() + dc.marshalNick(uc, nick)
|
members[i] = membership.String() + dc.marshalNick(uc, nick)
|
||||||
@ -850,7 +849,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
|||||||
}
|
}
|
||||||
ch.Status = status
|
ch.Status = status
|
||||||
|
|
||||||
for _, s := range strings.Split(members, " ") {
|
for _, s := range splitSpace(members) {
|
||||||
membership, nick := uc.parseMembershipPrefix(s)
|
membership, nick := uc.parseMembershipPrefix(s)
|
||||||
ch.Members[nick] = membership
|
ch.Members[nick] = membership
|
||||||
}
|
}
|
||||||
@ -995,7 +994,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
|||||||
if err := parseMessageParams(msg, nil, &nick, &channelList); err != nil {
|
if err := parseMessageParams(msg, nil, &nick, &channelList); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
channels := strings.Split(channelList, " ")
|
channels := splitSpace(channelList)
|
||||||
|
|
||||||
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
|
||||||
nick := dc.marshalNick(uc, nick)
|
nick := dc.marshalNick(uc, nick)
|
||||||
@ -1094,6 +1093,12 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func splitSpace(s string) []string {
|
||||||
|
return strings.FieldsFunc(s, func(r rune) bool {
|
||||||
|
return r == ' '
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (uc *upstreamConn) register() {
|
func (uc *upstreamConn) register() {
|
||||||
uc.nick = uc.network.Nick
|
uc.nick = uc.network.Nick
|
||||||
uc.username = uc.network.Username
|
uc.username = uc.network.Username
|
||||||
|
Loading…
Reference in New Issue
Block a user