1
0
Fork 0
forked from External/ergo

strings: disallow ':' in nicks

This matches the behavior of inspircd at the very least.

Previously, the comment above that section claimed ':' should be
disallowed, but the code didn't do so.

I also simplified the code a little bit and added tests.
This commit is contained in:
Euan Kemp 2017-07-25 23:02:35 -07:00
parent 9bb0062dbc
commit 449ef4cea1
2 changed files with 107 additions and 7 deletions

View file

@ -44,8 +44,7 @@ func CasefoldChannel(name string) (string, error) {
// , is used as a separator
// * is used in mask matching
// ? is used in mask matching
if strings.Contains(lowered, " ") || strings.Contains(lowered, ",") ||
strings.Contains(lowered, "*") || strings.Contains(lowered, "?") {
if strings.ContainsAny(lowered, " ,*?") {
return "", errInvalidCharacter
}
@ -73,11 +72,7 @@ func CasefoldName(name string) (string, error) {
// # is a channel prefix
// ~&@%+ are channel membership prefixes
// - I feel like disallowing
if strings.Contains(lowered, " ") || strings.Contains(lowered, ",") ||
strings.Contains(lowered, "*") || strings.Contains(lowered, "?") ||
strings.Contains(lowered, ".") || strings.Contains(lowered, "!") ||
strings.Contains(lowered, "@") ||
strings.Contains("#~&@%+-", string(lowered[0])) {
if strings.ContainsAny(lowered, " ,*?.!@:") || strings.ContainsAny(string(lowered[0]), "#~&@%+-") {
return "", errInvalidCharacter
}