Improve user nick validation
This commit is contained in:
parent
7b66778c84
commit
59e11fac4c
@ -5,6 +5,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/animenotifier/notify.moe/arn/autocorrect"
|
||||
)
|
||||
@ -31,6 +32,10 @@ func Nick(nick string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !utf8.ValidString(nick) {
|
||||
return false
|
||||
}
|
||||
|
||||
return nick == autocorrect.UserNick(nick)
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ func TestIsValidNick(t *testing.T) {
|
||||
assert.False(t, validate.Nick("Tsun.Dere"))
|
||||
assert.False(t, validate.Nick("Tsun Dere"))
|
||||
assert.False(t, validate.Nick("さとう"))
|
||||
assert.False(t, validate.Nick(string([]byte{0xff, 0xfe, 0xfd})))
|
||||
|
||||
// Valid nicknames
|
||||
assert.True(t, validate.Nick("Tsundere"))
|
||||
|
Loading…
Reference in New Issue
Block a user