Permalink
Browse files

uri_escape at directory-auto-index

  • Loading branch information...
1 parent b2c4aa2 commit 9da4e4b756af99bd716303757cf8f21e2372d0f1 @nihen nihen committed Sep 19, 2010
Showing with 31 additions and 0 deletions.
  1. +3 −0 lib/Plack/App/Directory.pm
  2. 0 share/#foo
  3. +28 −0 t/Plack-App/directory.t
@@ -6,6 +6,7 @@ use Plack::Util;
use HTTP::Date;
use Plack::MIME;
use DirHandle;
+use URI::Escape;
# Stolen from rack/directory.rb
my $dir_file = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>";
@@ -70,6 +71,8 @@ sub serve_path {
$url .= "/";
}
+ $url = join '/', map {uri_escape($_)} split m{/}, $url;
+
my $mime_type = $is_dir ? 'directory' : ( Plack::MIME->mime_type($file) || 'text/plain' );
push @files, [ $url, $basename, $stat[7], $mime_type, HTTP::Date::time2str($stat[9]) ];
}
View
No changes.
View
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+use Test::More;
+use HTTP::Request::Common;
+use HTTP::Response;
+use Plack::Test;
+use Plack::App::Directory;
+
+my $handler = Plack::App::Directory->new({ root => 'share' });
+
+
+my %test = (
+ client => sub {
+ my $cb = shift;
+
+ {
+ # URI-escape
+ my $res = $cb->(GET "http://localhost/");
+ my($ct, $charset) = $res->content_type;
+ ok $res->content =~ m{/%23foo};
+ }
+},
+ app => $handler,
+);
+
+test_psgi %test;
+
+done_testing;

0 comments on commit 9da4e4b

Please sign in to comment.