From 72ed15e174b467c60486ccdeeea65e8f13d60480 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sun, 16 Jun 2013 14:57:58 +0300 Subject: Make toUri sanitise all characters needed --- src/Hakyll/Web/Html.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Hakyll') diff --git a/src/Hakyll/Web/Html.hs b/src/Hakyll/Web/Html.hs index d06b7c2..3a0aa3b 100644 --- a/src/Hakyll/Web/Html.hs +++ b/src/Hakyll/Web/Html.hs @@ -30,6 +30,7 @@ import System.FilePath (joinPath, splitPath, import Text.Blaze.Html (toHtml) import Text.Blaze.Html.Renderer.String (renderHtml) import qualified Text.HTML.TagSoup as TS +import Network.URI (isUnreserved, escapeURIString) -------------------------------------------------------------------------------- @@ -105,10 +106,11 @@ toUrl url = case url of ('/' : xs) -> '/' : sanitize xs xs -> '/' : sanitize xs where - -- This probably needs to be a separate function - sanitize = concatMap $ \c -> case c of - ' ' -> "%20" - _ -> [c] + -- Everything but unreserved characters should be escaped as we are + -- sanitising the path therefore reserved characters which have a + -- meaning in URI does not appear. Special casing for `/`, because it has + -- a special meaning in FilePath as well as in URI. + sanitize = escapeURIString (\c -> c == '/' || isUnreserved c) -------------------------------------------------------------------------------- -- cgit v1.2.3