diff --git a/irc/strings.go b/irc/strings.go index f08823e0..3f9b82c4 100644 --- a/irc/strings.go +++ b/irc/strings.go @@ -7,6 +7,7 @@ package irc import ( "fmt" + "regexp" "strings" "unicode" @@ -21,6 +22,12 @@ const ( precisUTF8MappingToken = "rfc8265" ) +var ( + // reviving the old ergonomadic nickname regex: + // in permissive mode, allow arbitrary letters, numbers, punctuation, and symbols + permissiveCharsRegex = regexp.MustCompile(`^[\pL\pN\pP\pS]*$`) +) + type Casemapping uint const ( @@ -271,10 +278,8 @@ func IsPureASCII(str string) bool { } func foldPermissive(str string) (result string, err error) { - for _, r := range str { - if unicode.IsSpace(r) || r == 0 { - return "", errInvalidCharacter - } + if !permissiveCharsRegex.MatchString(str) { + return "", errInvalidCharacter } // YOLO str = norm.NFD.String(str) diff --git a/irc/strings_test.go b/irc/strings_test.go index 02e35305..6780186f 100644 --- a/irc/strings_test.go +++ b/irc/strings_test.go @@ -237,6 +237,7 @@ func TestFoldPermissive(t *testing.T) { tester("shivaram", "DAN-", false) tester("dolph🐬n", "DOLPH🐬n", true) tester("dolph🐬n", "dolph💻n", false) + tester("9FRONT", "9front", true) } func TestFoldPermissiveInvalid(t *testing.T) {