on master help sign in
Make toUri sanitise all characters needed
commit72ed15e174b467c60486ccdeeea65e8f13d60480 authorSimonas Kazlauskas <git@kazlauskas.me> dateSun 16 Jun 2013, 14:57 (13 years ago) parentd456f6e
2 files changed+10−6
hakyll.cabal+4−2 src/Hakyll/Web/Html.hs+6−4
hakyll.cabal+4−2
@@ -162,7 +162,8 @@ Library
162162 regex-tdfa >= 1.1 && < 1.2,
163163 tagsoup >= 0.12.6 && < 0.13,
164164 text >= 0.11 && < 1.12,
165− time >= 1.1 && < 1.5
165+ time >= 1.1 && < 1.5,
166+ network >= 2.0 && < 2.5
166167
167168 If flag(previewServer)
168169 Build-depends:
@@ -238,7 +239,8 @@ Test-suite hakyll-tests
238239 regex-tdfa >= 1.1 && < 1.2,
239240 tagsoup >= 0.12.6 && < 0.13,
240241 text >= 0.11 && < 1.12,
241− time >= 1.1 && < 1.5
242+ time >= 1.1 && < 1.5,
243+ network >= 2.0 && < 2.5
242244
243245 If flag(previewServer)
244246 Build-depends:
src/Hakyll/Web/Html.hs+6−4
@@ -30,6 +30,7 @@ import System.FilePath (joinPath, splitPath,
3030import Text.Blaze.Html (toHtml)
3131import Text.Blaze.Html.Renderer.String (renderHtml)
3232import qualified Text.HTML.TagSoup as TS
33+import Network.URI (isUnreserved, escapeURIString)
3334
3435
3536--------------------------------------------------------------------------------
@@ -105,10 +106,11 @@ toUrl url = case url of
105106 ('/' : xs) -> '/' : sanitize xs
106107 xs -> '/' : sanitize xs
107108 where
108− -- This probably needs to be a separate function
109− sanitize = concatMap $ \c -> case c of
110− ' ' -> "%20"
111− _ -> [c]
109+ -- Everything but unreserved characters should be escaped as we are
110+ -- sanitising the path therefore reserved characters which have a
111+ -- meaning in URI does not appear. Special casing for `/`, because it has
112+ -- a special meaning in FilePath as well as in URI.
113+ sanitize = escapeURIString (\c -> c == '/' || isUnreserved c)
112114
113115
114116--------------------------------------------------------------------------------