From 340058cb2e41797b648a5e29cf3c911bfe602633 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 11 Sep 2020 13:52:04 +0200 Subject: Restrict room names to ASCII Fixes #4 --- server/lib/Uplcg/Main/Server.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'server/lib') diff --git a/server/lib/Uplcg/Main/Server.hs b/server/lib/Uplcg/Main/Server.hs index 6527251..9b3fa56 100644 --- a/server/lib/Uplcg/Main/Server.hs +++ b/server/lib/Uplcg/Main/Server.hs @@ -17,7 +17,7 @@ import Data.Bifunctor (first, second) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as BC import qualified Data.ByteString.Lazy as BL -import Data.Char (isAlphaNum) +import Data.Char (isAlphaNum, isAscii) import Data.Foldable (for_) import Data.Hashable (Hashable) import qualified Data.HashMap.Strict as HMS @@ -80,12 +80,13 @@ newRoom rid rpw cards gen = Room rid rpw parseRoomId :: T.Text -> Either String RoomId parseRoomId txt - | not (T.all isAlphaNum txt) = Left "please use alphanum characters only" - | l < 1 = Left "minimum length of 1" - | l > 32 = Left "maximum length of 32" - | otherwise = Right $ RoomId txt + | not (T.all valid txt) = Left "please use ASCII alphanum characters only" + | l < 1 = Left "minimum length of 1" + | l > 32 = Left "maximum length of 32" + | otherwise = Right $ RoomId txt where l = T.length txt + valid c = isAlphaNum c && isAscii c parseRoomPassword :: T.Text -> Either String RoomPassword parseRoomPassword txt -- cgit v1.2.3