on master help sign in
Sanitize URLs in toUrl

Closes #163

commit537e72333f8deafa59219b60dcae0a4f52569317 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 15 Jun 2013, 20:15 (13 years ago) parenta591b16
2 files changed+14−5
src/Hakyll/Web/Html.hs+10−2 tests/Hakyll/Web/Html/Tests.hs+4−3
src/Hakyll/Web/Html.hs+10−2
@@ -98,9 +98,17 @@ renderTags' = TS.renderTagsOptions TS.renderOptions
9898-- Result:
9999--
100100-- > "/foo/bar.html"
101+--
102+-- This also sanitizes the URL, e.g. converting spaces into '%20'
101103toUrl :: FilePath -> String
102−toUrl ('/' : xs) = '/' : xs
103−toUrl url = '/' : url
104+toUrl url = case url of
105+ ('/' : xs) -> '/' : sanitize xs
106+ xs -> '/' : sanitize xs
107+ where
108+ -- This probably needs to be a separate function
109+ sanitize = concatMap $ \c -> case c of
110+ ' ' -> "%20"
111+ _ -> [c]
104112
105113
106114--------------------------------------------------------------------------------
tests/Hakyll/Web/Html/Tests.hs+4−3
@@ -43,9 +43,10 @@ tests = testGroup "Hakyll.Web.Html.Tests" $ concat
4343 ]
4444
4545 , fromAssertions "toUrl"
46− [ "/foo/bar.html" @=? toUrl "foo/bar.html"
47− , "/" @=? toUrl "/"
48− , "/funny-pics.html" @=? toUrl "/funny-pics.html"
46+ [ "/foo/bar.html" @=? toUrl "foo/bar.html"
47+ , "/" @=? toUrl "/"
48+ , "/funny-pics.html" @=? toUrl "/funny-pics.html"
49+ , "/funny%20pics.html" @=? toUrl "funny pics.html"
4950 ]
5051
5152 , fromAssertions "toSiteRoot"