Skip to content

Commit

Permalink
Fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
laserpants committed Aug 31, 2023
1 parent a3c5497 commit 2838568
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Web/Sqids/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ instance (MonadSqids m) => MonadSqids (SelectT r m) where
-- 3. Remove words that contain characters that are not in the alphabet
--
filteredBlocklist :: Text -> [Text] -> [Text]
filteredBlocklist alph ws = (Text.map toLower) <$> filter isValid ws where
isValid w = Text.length w >= 3 && Text.all (`Text.elem` alph) w
filteredBlocklist alph ws = filter isValid (Text.map toLower <$> ws) where
isValid w = Text.length w >= 3 && Text.all (`Text.elem` lowercaseAlphabet) w
lowercaseAlphabet = Text.map toLower alph

decodeStep :: (Text, Text) -> Maybe (Int, (Text, Text))
decodeStep (sqid, alph)
Expand Down
8 changes: 8 additions & 0 deletions test/Web/Sqids/BlocklistTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ testBlocklist = do

it "match against a short blocklist word" $
withCustomBlocklist [ "pPQ" ] ((encode >=> decode) [1000]) `shouldBe` Right [1000]

it "blocklist filtering in constructor" $ do
let options = defaultSqidsOptions { alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", blocklist = ["sqnmpn"] }
testFn = do
p <- encode [1, 2, 3]
q <- decode p
pure (p, q)
runSqids options testFn `shouldBe` Right ("ULPBZGBM", [1, 2, 3])

0 comments on commit 2838568

Please sign in to comment.