Improve user nick validation

This commit is contained in:
Eduard Urbach 2019-11-17 15:45:02 +09:00
parent 7b66778c84
commit 59e11fac4c
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 6 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"time" "time"
"unicode/utf8"
"github.com/animenotifier/notify.moe/arn/autocorrect" "github.com/animenotifier/notify.moe/arn/autocorrect"
) )
@ -31,6 +32,10 @@ func Nick(nick string) bool {
return false return false
} }
if !utf8.ValidString(nick) {
return false
}
return nick == autocorrect.UserNick(nick) return nick == autocorrect.UserNick(nick)
} }

View File

@ -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("Tsun Dere")) assert.False(t, validate.Nick("Tsun Dere"))
assert.False(t, validate.Nick("さとう")) assert.False(t, validate.Nick("さとう"))
assert.False(t, validate.Nick(string([]byte{0xff, 0xfe, 0xfd})))
// Valid nicknames // Valid nicknames
assert.True(t, validate.Nick("Tsundere")) assert.True(t, validate.Nick("Tsundere"))