Skip to content

Commit 62dfeee

Browse files
committed
Handle umlaute and non ascii chars in toSlug
1 parent bc2b663 commit 62dfeee

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

IHP/NameSupport.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,16 @@ haskellKeywords = [ "_"
235235
-- "hallo-welt"
236236
toSlug :: Text -> Text
237237
toSlug text =
238-
text
239-
|> map (\char -> if Char.isAlphaNum char then char else ' ')
240-
|> toLower
241-
|> words
242-
|> intercalate "-"
238+
text
239+
|> toLower
240+
|> map replaceChar
241+
|> words
242+
|> intercalate "-"
243+
where
244+
replaceChar 'ä' = 'a'
245+
replaceChar 'ö' = 'o'
246+
replaceChar 'ü' = 'u'
247+
replaceChar char = if Char.isAlphaNum char && Char.isAscii char then char else ' '
243248

244249

245250
-- | Transform a data-field name like @userName@ to a friendly human-readable name like @User name@

Test/NameSupportSpec.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ tests = do
111111
it "should make a slug string from a string" do
112112
toSlug "IHP Release: 21.08.2020 (v21082020)" `shouldBe` "ihp-release-21-08-2020-v21082020"
113113
toSlug "Hallo! @ Welt" `shouldBe` "hallo-welt"
114+
115+
it "should deal with umlaute" do
116+
toSlug "käuferpass" `shouldBe` "kauferpass"
117+
toSlug "äöü" `shouldBe` "aou"

0 commit comments

Comments
 (0)