@@ -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--------------------------------------------------------------------------------