snapframework/snap-core — Issue #121: defaultIndexGenerator - wrong directory links
Author: rmoorman
Created: 2012-02-10 19:48:52+00:00
State: open

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](http://snapframework.com/docs/tutorials/snap-api) I could reproduce this behaviour.
I made the default routes look like this:

````haskell
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) 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
Date: Thu, 9 Feb 2012 16: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 "
"
+ writeBS "'>"
writeBS f
writeBS "	DIR
"

--
1.7.2.5
````

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

Keep up the great work.