mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
restrict ASCII mode to printable characters only
This commit is contained in:
parent
781bb6b051
commit
4391b1ba5a
2 changed files with 42 additions and 16 deletions
|
|
@ -9,7 +9,6 @@ import (
|
|||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/oragono/confusables"
|
||||
"golang.org/x/text/cases"
|
||||
|
|
@ -262,15 +261,18 @@ func CanonicalizeMaskWildcard(userhost string) (expanded string, err error) {
|
|||
}
|
||||
|
||||
func foldASCII(str string) (result string, err error) {
|
||||
if !IsPureASCII(str) {
|
||||
if !IsPrintableASCII(str) {
|
||||
return "", errInvalidCharacter
|
||||
}
|
||||
return strings.ToLower(str), nil
|
||||
}
|
||||
|
||||
func IsPureASCII(str string) bool {
|
||||
func IsPrintableASCII(str string) bool {
|
||||
for i := 0; i < len(str); i++ {
|
||||
if unicode.MaxASCII < str[i] {
|
||||
// allow space here because it's technically printable;
|
||||
// it will be disallowed later by CasefoldName/CasefoldChannel
|
||||
chr := str[i]
|
||||
if chr < ' ' || chr > '~' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue