3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

disallow some bad characters in foldPermissive

This commit is contained in:
Shivaram Lingamneni 2019-12-22 09:19:28 -05:00
parent 0df25e0e30
commit 2d4dbeba1c
2 changed files with 17 additions and 0 deletions

View File

@ -271,6 +271,11 @@ 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 unicode.IsSpace(r) || r == 0 {
return "", errInvalidCharacter
}
}
// YOLO // YOLO
str = norm.NFD.String(str) str = norm.NFD.String(str)
str = cases.Fold().String(str) str = cases.Fold().String(str)

View File

@ -63,6 +63,7 @@ func TestCasefoldChannel(t *testing.T) {
"", "#*starpower", "# NASA", "#interro?", "OOF#", "foo", "", "#*starpower", "# NASA", "#interro?", "OOF#", "foo",
// bidi violation mixing latin and hebrew characters: // bidi violation mixing latin and hebrew characters:
"#shalomעליכם", "#shalomעליכם",
"#tab\tcharacter", "#\t", "#carriage\rreturn",
} { } {
testCases = append(testCases, channelTest{channel: errCase, err: true}) 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", true)
tester("dolph🐬n", "dolph💻n", false) 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")
}
}