1
0
Fork 0
forked from External/ergo

Restrict idents as other servers do

This commit is contained in:
Daniel Oaks 2019-02-03 18:49:42 +10:00
parent 9f25a42c3d
commit 8cd5db1194
5 changed files with 49 additions and 4 deletions

View file

@ -128,6 +128,32 @@ func isBoring(name string) bool {
return true
}
// returns true if the given name is a valid ident, using a mix of Insp and
// Chary's ident restrictions.
func isIdent(name string) bool {
if len(name) < 1 {
return false
}
for i := 0; i < len(name); i++ {
chr := name[i]
if (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') {
continue // alphanumerics
}
if i == 0 {
return false // first char must be alnum
}
switch chr {
case '[', '\\', ']', '^', '_', '{', '|', '}', '-', '.', '`':
continue // allowed chars
default:
return false // disallowed chars
}
}
return true
}
// Skeleton produces a canonicalized identifier that tries to catch
// homoglyphic / confusable identifiers. It's a tweaked version of the TR39
// skeleton algorithm. We apply the skeleton algorithm first and only then casefold,