defaultIndexGenerator - wrong directory links #121

Closed
rmoorman opened this Issue Feb 10, 2012 · 2 comments

Projects

None yet

2 participants

@rmoorman

Hello,

Some time ago I spotted an issue within the directory serving functionality of snap while using hakyll. I actually had a directory structure generated (and served by snap) which was several levels deep.
Snap provided me with the fancy directory index but then I noticed that the links to subdirectories were wrong. The links had a double slash at the end.

I decided to investigate a little more what was going on and tried if I could reproduce this with a default snap installation. Using the snap api tutorial I could reproduce this behaviour.
I made the default routes look like this:

routes :: [(ByteString, Handler App App ())]
routes = [ ("/",            index)
         , ("/echo/:stuff", echo)
         , ("", with heist heistServe)
         , ("", serveDirectory "resources/static")
         , ("r", serveDirectoryWith fancyDirectoryConfig "./")
         ]

Running the application and visiting (in my case) http://localhost:8000/r/ generated the same double slashes.

The following patch resulted in correct links for me.

From f4617e823b36ec4164611729a8a885b7165f3f5e Mon Sep 17 00:00:00 2001
From: R. Moorman <rico.moorman@gmail.com>
Date: Fri, 10 Feb 2012 19:50:46 +0100
Subject: [PATCH] Adjusted directory link href to contain only one forward slash.

---
 src/Snap/Util/FileServe.hs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/Snap/Util/FileServe.hs b/src/Snap/Util/FileServe.hs
index 134f651..e92c263 100644
--- a/src/Snap/Util/FileServe.hs
+++ b/src/Snap/Util/FileServe.hs
@@ -324,7 +324,7 @@ defaultIndexGenerator mm styles d = do
         f <- liftIO $ liftM (\s -> T.encodeUtf8 s `mappend` "/") $ packFn f0
         writeBS "<tr><td class='filename'><a href='"
         writeBS f
-        writeBS "/'>"
+        writeBS "'>"
         writeBS f
         writeBS "</a></td><td class='type' colspan=2>DIR</td></tr>"

-- 
1.7.2.5

I hope this helps and thank you very much in advance.

Keep up the great work.

@mightybyte
Snap Framework member

Can you retry your code without the patch on snap-core but with "." instead of "./" in the call to serveDirectoryWith?

@rmoorman

This yields the same result. I think the issue is that the HTML within the function appends a slash to a string which already was sufficiently suffixed with a slash using mappend "/" in one of the lines above.

@mightybyte mightybyte closed this Feb 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment