aboutsummaryrefslogtreecommitdiff
path: root/server/lib
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-09-11 13:52:04 +0200
committerJasper Van der Jeugt2020-09-11 13:52:04 +0200
commit340058cb2e41797b648a5e29cf3c911bfe602633 (patch)
tree51e534d0ba7abd49f57246793d3b821d5cb3a4e1 /server/lib
parent876c02475b526d3498fa28223ef85cc57e8591b9 (diff)
Restrict room names to ASCII
Fixes #4
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/Uplcg/Main/Server.hs11
1 files changed, 6 insertions, 5 deletions
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