on master help sign in
3 files changed+19−10
since splitsnapshots
unifiedsplit
denis/src/Data/PostElement.hs+8−2 denis/src/Data/Query.hs+5−5 denis/src/Data/Tags/Validation.hs+6−3
denis/src/Data/PostElement.hs+8−2
@@ -16,13 +16,14 @@ module Data.PostElement (
1616 PostElementRow(..),
1717 PostElement(..),
1818 elementsToRows,
19− PostQuote(..)
19+ PostQuote(..),
20+ stripPostElement
2021) where
2122
2223import Data.Int (Int64)
2324import qualified Generics.SOP as SOP
2425import qualified GHC.Generics as GHC
25−import Data.Text (Text)
26+import Data.Text (Text, strip)
2627import Data.Aeson
2728import Control.Applicative ((<|>))
2829import Servant.Docs (ToSample, toSamples, samples)
@@ -54,6 +55,11 @@ data PostElement a = Markdown Text
5455 | Attachment Text
5556 deriving (Show, GHC.Generic)
5657
58+stripPostElement :: (PostElement a) -> (PostElement a)
59+stripPostElement (Markdown t) = Markdown (strip t)
60+stripPostElement (Latex t) = Latex (strip t)
61+stripPostElement u = u
62+
5763instance ToJSON (PostElement t) where
5864 toJSON (Markdown m) = object ["markdown" .= m]
5965 toJSON (Latex l) = object ["latex" .= l]
denis/src/Data/Query.hs+5−5
@@ -935,7 +935,7 @@ publishPost uId pc = commitedTransactionallyUpdate $ do
935935 pId' <- manipulateParams createPostRowQ (uId, postCreationTags pc) >>= firstRow
936936 case pId' of
937937 (Just (Only pId)) -> do
938− traversePrepared_ createPostElementRowsQ $ elementsToRows pId (postCreationBody pc)
938+ traversePrepared_ createPostElementRowsQ $ elementsToRows pId (map stripPostElement $ postCreationBody pc)
939939 return pId
940940 _ -> lift $ S.throwError S.err404
941941
@@ -1043,14 +1043,14 @@ getMessagesInGroupChat selfId gId mId lim dir = do
10431043 return . catMaybes . map restoreMessage $ resp
10441044
10451045sendMessage :: UserId -> MessageCreation -> StaticPQ MessageId
1046−sendMessage selfId (MessageCreation (Just gId) uId@Nothing body) = do
1046+sendMessage selfId (MessageCreation (Just gId) uId@Nothing (Jsonb body)) = do
10471047 _ <- getGroupChatForUser selfId gId
1048− (Only mId) <- manipulateParams createMessageQ (selfId, Just gId, uId, body)
1048+ (Only mId) <- manipulateParams createMessageQ (selfId, Just gId, uId, Jsonb $ stripPostElement body)
10491049 >>= firstRow >>= fromMaybe500
10501050 return mId
1051−sendMessage selfId (MessageCreation gId@Nothing (Just uId) body) = do
1051+sendMessage selfId (MessageCreation gId@Nothing (Just uId) (Jsonb body)) = do
10521052 verifyUsers [uId]
1053− (Only mId) <- manipulateParams createMessageQ (selfId, gId, Just uId, body)
1053+ (Only mId) <- manipulateParams createMessageQ (selfId, gId, Just uId, Jsonb $ stripPostElement body)
10541054 >>= firstRow >>= fromMaybe500
10551055 return mId
10561056sendMessage _ _ = lift $ S.throwError S.err400
denis/src/Data/Tags/Validation.hs+6−3
@@ -4,7 +4,8 @@ module Data.Tags.Validation (
44 ) where
55
66import Data.Text as T
7−import Data.Char
7+import Data.Char as C
8+import qualified Data.Set as S
89
910validateTag :: T.Text -> Maybe T.Text
1011validateTag tag =
@@ -17,6 +18,8 @@ validateTag tag =
1718validateTag' :: T.Text -> Bool
1819validateTag' = T.all validChar
1920
21+validChars :: S.Set Char
22+validChars = S.fromList "йцукенгшщзхъфывапролджэёячсмитьбюqwertyuiopasdfghjklzxcvbnm1234567890_"
23+
2024validChar :: Char -> Bool
21−validChar '-' = True
22−validChar c = isAlphaNum c
25+validChar c = S.member (C.toLower c) validChars