[Mongrel] DirHandler escaping (patch)

carmen _ at whats-your.name
Mon Aug 7 14:11:40 EDT 2006


fiddled around a bit and got DirGHandler to work for both files and directories with spaces in them, and plusses in them (on disk). 

eg:

<a href="/files/usr/portage/packages/All/gtk%2B-2.10.1.tbz2">gtk+-2.10.1.tbz2</a><br/>
<a href="/files/root/hey+whatsthis+dir">hey whatsthis dir</a>

both end up at the right place now..

..c.
-------------- next part --------------
--- /a/usr/lib/ruby/gems/1.8/gems/mongrel-0.3.13.3/lib/mongrel/handlers.rb	2006-08-07 12:26:22.000000000 -0400
+++ ./handlers.rb	2006-08-07 13:36:14.000000000 -0400
@@ -173,14 +173,10 @@
           head[Const::CONTENT_TYPE] = "text/html"
           out << "<html><head><title>Directory Listing</title></head><body>"
           Dir.entries(dir).each do |child|
-            child = HttpRequest.unescape(child)
             next if child == "."
-
-            if child == ".."
-              out << "<a href=\"#{base}/#{child}\">Up to parent..</a><br/>"
-            else
-              out << "<a href=\"#{base}/#{child}/\">#{child}</a><br/>"
-            end
+            out << "<a href=\"#{base}/#{ HttpRequest.escape(child)}\">"
+            out << (child == ".." ? "Up to parent.." : child)
+            out << "</a><br/>"
           end
           out << "</body></html>"
         end


More information about the Mongrel-users mailing list