mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
more systematic bad-character check in permissive mode
This commit is contained in:
parent
2d4dbeba1c
commit
781bb6b051
@ -7,6 +7,7 @@ package irc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@ -21,6 +22,12 @@ const (
|
|||||||
precisUTF8MappingToken = "rfc8265"
|
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
|
type Casemapping uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -271,10 +278,8 @@ func IsPureASCII(str string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func foldPermissive(str string) (result string, err error) {
|
func foldPermissive(str string) (result string, err error) {
|
||||||
for _, r := range str {
|
if !permissiveCharsRegex.MatchString(str) {
|
||||||
if unicode.IsSpace(r) || r == 0 {
|
return "", errInvalidCharacter
|
||||||
return "", errInvalidCharacter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// YOLO
|
// YOLO
|
||||||
str = norm.NFD.String(str)
|
str = norm.NFD.String(str)
|
||||||
|
@ -237,6 +237,7 @@ func TestFoldPermissive(t *testing.T) {
|
|||||||
tester("shivaram", "DAN-", false)
|
tester("shivaram", "DAN-", false)
|
||||||
tester("dolph🐬n", "DOLPH🐬n", true)
|
tester("dolph🐬n", "DOLPH🐬n", true)
|
||||||
tester("dolph🐬n", "dolph💻n", false)
|
tester("dolph🐬n", "dolph💻n", false)
|
||||||
|
tester("9FRONT", "9front", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFoldPermissiveInvalid(t *testing.T) {
|
func TestFoldPermissiveInvalid(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user