3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-02-18 06:30:39 +01:00

strings: Disallow nicknames that mess with the protocol in bad ways

This commit is contained in:
Daniel Oaks 2016-04-12 22:40:58 +10:00
parent 65539a593b
commit 7ce62444de

View File

@ -1,9 +1,10 @@
package irc package irc
import ( import (
"golang.org/x/text/unicode/norm"
"regexp" "regexp"
"strings" "strings"
"golang.org/x/text/unicode/norm"
) )
var ( var (
@ -35,7 +36,15 @@ func (name Name) IsChannel() bool {
} }
func (name Name) IsNickname() bool { func (name Name) IsNickname() bool {
return NicknameExpr.MatchString(name.String()) namestr := name.String()
// * is used for unregistered clients
// , is used as a separator by the protocol
// # is a channel prefix
// @+ are channel membership prefixes
if namestr == "*" || strings.Contains(namestr, ",") || strings.Contains("#@+", string(namestr[0])) {
return false
}
return NicknameExpr.MatchString(namestr)
} }
// conversions // conversions