summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2013-06-16 14:57:58 +0300
committerSimonas Kazlauskas <git@kazlauskas.me>2013-06-16 15:11:04 +0300
commit72ed15e174b467c60486ccdeeea65e8f13d60480 (patch)
tree30f2132e232adde04e20c2eef0e44f6283a05296
parentd456f6ebf724fc83b7c23fa9625b0b484acc1f00 (diff)
downloadhakyll-72ed15e174b467c60486ccdeeea65e8f13d60480.tar.gz
Make toUri sanitise all characters needed
-rw-r--r--hakyll.cabal6
-rw-r--r--src/Hakyll/Web/Html.hs10
2 files changed, 10 insertions, 6 deletions
diff --git a/hakyll.cabal b/hakyll.cabal
index 633a414..8daface 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -162,7 +162,8 @@ Library
regex-tdfa >= 1.1 && < 1.2,
tagsoup >= 0.12.6 && < 0.13,
text >= 0.11 && < 1.12,
- time >= 1.1 && < 1.5
+ time >= 1.1 && < 1.5,
+ network >= 2.0 && < 2.5
If flag(previewServer)
Build-depends:
@@ -238,7 +239,8 @@ Test-suite hakyll-tests
regex-tdfa >= 1.1 && < 1.2,
tagsoup >= 0.12.6 && < 0.13,
text >= 0.11 && < 1.12,
- time >= 1.1 && < 1.5
+ time >= 1.1 && < 1.5,
+ network >= 2.0 && < 2.5
If flag(previewServer)
Build-depends:
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)
--------------------------------------------------------------------------------