summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2013-06-16 09:05:41 -0700
committerJasper Van der Jeugt <jaspervdj@gmail.com>2013-06-16 09:05:41 -0700
commit832c6d3f9a150ed17c230a156230ca5556aa2250 (patch)
tree30f2132e232adde04e20c2eef0e44f6283a05296 /src/Hakyll
parent537e72333f8deafa59219b60dcae0a4f52569317 (diff)
parent72ed15e174b467c60486ccdeeea65e8f13d60480 (diff)
downloadhakyll-832c6d3f9a150ed17c230a156230ca5556aa2250.tar.gz
Merge pull request #165 from nagisa/uri-sanitise
Better sanitising for URIs
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/Html.hs10
1 files changed, 6 insertions, 4 deletions
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)
--------------------------------------------------------------------------------