allow only a-zA-Z for keyboard layout

This commit is contained in:
Miroslav Šedivý 2020-06-16 02:39:15 +02:00
parent e6c7dd0122
commit fcca903ae9

View File

@ -13,6 +13,7 @@ import (
"sync" "sync"
"time" "time"
"unsafe" "unsafe"
"regexp"
"n.eko.moe/neko/internal/types" "n.eko.moe/neko/internal/types"
) )
@ -214,6 +215,10 @@ func SetKeyboard(layout string) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
if !regexp.MustCompile(`^[a-zA-Z]+$`).MatchString(layout) {
return
}
layoutUnsafe := C.CString(layout) layoutUnsafe := C.CString(layout)
defer C.free(unsafe.Pointer(layoutUnsafe)) defer C.free(unsafe.Pointer(layoutUnsafe))