1
0
Fork 0
forked from External/ergo

more systematic bad-character check in permissive mode

This commit is contained in:
Shivaram Lingamneni 2019-12-22 09:31:51 -05:00
parent 2d4dbeba1c
commit 781bb6b051
2 changed files with 10 additions and 4 deletions

View file

@ -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)