mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
disallow some bad characters in foldPermissive
This commit is contained in:
parent
0df25e0e30
commit
2d4dbeba1c
@ -271,6 +271,11 @@ 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
|
||||
}
|
||||
}
|
||||
// YOLO
|
||||
str = norm.NFD.String(str)
|
||||
str = cases.Fold().String(str)
|
||||
|
@ -63,6 +63,7 @@ func TestCasefoldChannel(t *testing.T) {
|
||||
"", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
|
||||
// bidi violation mixing latin and hebrew characters:
|
||||
"#shalomעליכם",
|
||||
"#tab\tcharacter", "#\t", "#carriage\rreturn",
|
||||
} {
|
||||
testCases = append(testCases, channelTest{channel: errCase, err: true})
|
||||
}
|
||||
@ -237,3 +238,14 @@ func TestFoldPermissive(t *testing.T) {
|
||||
tester("dolph🐬n", "DOLPH🐬n", true)
|
||||
tester("dolph🐬n", "dolph💻n", false)
|
||||
}
|
||||
|
||||
func TestFoldPermissiveInvalid(t *testing.T) {
|
||||
_, err := foldPermissive("a\tb")
|
||||
if err == nil {
|
||||
t.Errorf("whitespace should be invalid in identifiers")
|
||||
}
|
||||
_, err = foldPermissive("a\x00b")
|
||||
if err == nil {
|
||||
t.Errorf("the null byte should be invalid in identifiers")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user